<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv='Content-Type' content='text/html; charset=utf-8'>
<title>Coverage for functest_modbus</title>
<link rel='stylesheet' href='style.css' type='text/css'>
<script type='text/javascript' src='jquery-1.3.2.min.js'></script>
<script type='text/javascript'>
function toggle_lines(btn, cls) {
    var btn = $(btn);
    var hide = "hide_"+cls;
    if (btn.hasClass(hide)) {
        $("#source ."+cls).removeClass(hide);
        btn.removeClass(hide);
    }
    else {
        $("#source ."+cls).addClass(hide);
        btn.addClass(hide);
    }
}
</script>
</head>
<body>
<div id='header'>
    <div class='content'>
        <h1>Coverage for <b>functest_modbus</b> :
            <span class='pc_cov'>96%</span>
        </h1>
        <h2 class='stats'>
            250 statements
            <span class='run hide_run' onclick='toggle_lines(this, "run")'>239 run</span>
            <span class='exc' onclick='toggle_lines(this, "exc")'>0 excluded</span>
            <span class='mis' onclick='toggle_lines(this, "mis")'>11 missing</span>
            
                <span class='par run hide_run' onclick='toggle_lines(this, "par")'>0 partial</span>
            
        </h2>
    </div>
</div>

<div id='source'>
<table cellspacing='0' cellpadding='0'>
<tr>
<td class='linenos' valign='top'>
<p class='pln'>1</p>
<p class='pln'>2</p>
<p class='stm run hide_run'>3</p>
<p class='pln'>4</p>
<p class='pln'>5</p>
<p class='pln'>6</p>
<p class='pln'>7</p>
<p class='pln'>8</p>
<p class='pln'>9</p>
<p class='pln'>10</p>
<p class='pln'>11</p>
<p class='stm run hide_run'>12</p>
<p class='stm run hide_run'>13</p>
<p class='stm run hide_run'>14</p>
<p class='stm run hide_run'>15</p>
<p class='stm run hide_run'>16</p>
<p class='stm run hide_run'>17</p>
<p class='stm run hide_run'>18</p>
<p class='stm run hide_run'>19</p>
<p class='stm run hide_run'>20</p>
<p class='pln'>21</p>
<p class='stm run hide_run'>22</p>
<p class='pln'>23</p>
<p class='stm run hide_run'>24</p>
<p class='pln'>25</p>
<p class='pln'>26</p>
<p class='stm run hide_run'>27</p>
<p class='stm run hide_run'>28</p>
<p class='stm run hide_run'>29</p>
<p class='pln'>30</p>
<p class='stm run hide_run'>31</p>
<p class='stm run hide_run'>32</p>
<p class='stm run hide_run'>33</p>
<p class='stm run hide_run'>34</p>
<p class='stm run hide_run'>35</p>
<p class='stm run hide_run'>36</p>
<p class='stm run hide_run'>37</p>
<p class='stm run hide_run'>38</p>
<p class='stm run hide_run'>39</p>
<p class='pln'>40</p>
<p class='stm run hide_run'>41</p>
<p class='stm run hide_run'>42</p>
<p class='pln'>43</p>
<p class='stm run hide_run'>44</p>
<p class='stm run hide_run'>45</p>
<p class='stm run hide_run'>46</p>
<p class='stm run hide_run'>47</p>
<p class='pln'>48</p>
<p class='stm run hide_run'>49</p>
<p class='stm run hide_run'>50</p>
<p class='stm run hide_run'>51</p>
<p class='pln'>52</p>
<p class='stm run hide_run'>53</p>
<p class='pln'>54</p>
<p class='pln'>55</p>
<p class='pln'>56</p>
<p class='stm run hide_run'>57</p>
<p class='pln'>58</p>
<p class='stm run hide_run'>59</p>
<p class='stm run hide_run'>60</p>
<p class='stm run hide_run'>61</p>
<p class='pln'>62</p>
<p class='stm run hide_run'>63</p>
<p class='stm run hide_run'>64</p>
<p class='stm run hide_run'>65</p>
<p class='pln'>66</p>
<p class='stm run hide_run'>67</p>
<p class='pln'>68</p>
<p class='stm run hide_run'>69</p>
<p class='stm run hide_run'>70</p>
<p class='stm run hide_run'>71</p>
<p class='stm run hide_run'>72</p>
<p class='stm run hide_run'>73</p>
<p class='stm mis'>74</p>
<p class='pln'>75</p>
<p class='stm run hide_run'>76</p>
<p class='pln'>77</p>
<p class='stm run hide_run'>78</p>
<p class='stm run hide_run'>79</p>
<p class='stm run hide_run'>80</p>
<p class='pln'>81</p>
<p class='stm run hide_run'>82</p>
<p class='pln'>83</p>
<p class='stm run hide_run'>84</p>
<p class='pln'>85</p>
<p class='stm run hide_run'>86</p>
<p class='stm run hide_run'>87</p>
<p class='pln'>88</p>
<p class='stm run hide_run'>89</p>
<p class='pln'>90</p>
<p class='stm run hide_run'>91</p>
<p class='pln'>92</p>
<p class='stm run hide_run'>93</p>
<p class='stm run hide_run'>94</p>
<p class='pln'>95</p>
<p class='stm run hide_run'>96</p>
<p class='pln'>97</p>
<p class='stm run hide_run'>98</p>
<p class='pln'>99</p>
<p class='stm run hide_run'>100</p>
<p class='stm run hide_run'>101</p>
<p class='stm run hide_run'>102</p>
<p class='stm run hide_run'>103</p>
<p class='stm run hide_run'>104</p>
<p class='stm mis'>105</p>
<p class='pln'>106</p>
<p class='stm run hide_run'>107</p>
<p class='pln'>108</p>
<p class='stm run hide_run'>109</p>
<p class='stm run hide_run'>110</p>
<p class='stm run hide_run'>111</p>
<p class='stm run hide_run'>112</p>
<p class='stm run hide_run'>113</p>
<p class='stm mis'>114</p>
<p class='pln'>115</p>
<p class='stm run hide_run'>116</p>
<p class='pln'>117</p>
<p class='stm run hide_run'>118</p>
<p class='stm run hide_run'>119</p>
<p class='stm run hide_run'>120</p>
<p class='stm run hide_run'>121</p>
<p class='stm run hide_run'>122</p>
<p class='pln'>123</p>
<p class='stm run hide_run'>124</p>
<p class='pln'>125</p>
<p class='stm run hide_run'>126</p>
<p class='stm run hide_run'>127</p>
<p class='stm run hide_run'>128</p>
<p class='stm run hide_run'>129</p>
<p class='stm run hide_run'>130</p>
<p class='stm run hide_run'>131</p>
<p class='stm run hide_run'>132</p>
<p class='stm run hide_run'>133</p>
<p class='stm run hide_run'>134</p>
<p class='stm run hide_run'>135</p>
<p class='stm run hide_run'>136</p>
<p class='stm run hide_run'>137</p>
<p class='stm run hide_run'>138</p>
<p class='pln'>139</p>
<p class='stm run hide_run'>140</p>
<p class='pln'>141</p>
<p class='stm run hide_run'>142</p>
<p class='pln'>143</p>
<p class='stm run hide_run'>144</p>
<p class='stm run hide_run'>145</p>
<p class='stm run hide_run'>146</p>
<p class='pln'>147</p>
<p class='stm run hide_run'>148</p>
<p class='stm run hide_run'>149</p>
<p class='stm run hide_run'>150</p>
<p class='pln'>151</p>
<p class='stm run hide_run'>152</p>
<p class='stm run hide_run'>153</p>
<p class='stm run hide_run'>154</p>
<p class='pln'>155</p>
<p class='stm run hide_run'>156</p>
<p class='stm run hide_run'>157</p>
<p class='stm run hide_run'>158</p>
<p class='pln'>159</p>
<p class='stm run hide_run'>160</p>
<p class='pln'>161</p>
<p class='stm run hide_run'>162</p>
<p class='stm run hide_run'>163</p>
<p class='stm run hide_run'>164</p>
<p class='stm run hide_run'>165</p>
<p class='stm run hide_run'>166</p>
<p class='stm mis'>167</p>
<p class='pln'>168</p>
<p class='stm run hide_run'>169</p>
<p class='pln'>170</p>
<p class='stm run hide_run'>171</p>
<p class='stm run hide_run'>172</p>
<p class='stm run hide_run'>173</p>
<p class='stm run hide_run'>174</p>
<p class='stm run hide_run'>175</p>
<p class='stm mis'>176</p>
<p class='pln'>177</p>
<p class='stm run hide_run'>178</p>
<p class='pln'>179</p>
<p class='stm run hide_run'>180</p>
<p class='stm run hide_run'>181</p>
<p class='stm run hide_run'>182</p>
<p class='stm run hide_run'>183</p>
<p class='stm run hide_run'>184</p>
<p class='stm run hide_run'>185</p>
<p class='stm run hide_run'>186</p>
<p class='stm run hide_run'>187</p>
<p class='stm run hide_run'>188</p>
<p class='stm run hide_run'>189</p>
<p class='stm run hide_run'>190</p>
<p class='stm run hide_run'>191</p>
<p class='stm run hide_run'>192</p>
<p class='stm run hide_run'>193</p>
<p class='pln'>194</p>
<p class='stm run hide_run'>195</p>
<p class='pln'>196</p>
<p class='stm run hide_run'>197</p>
<p class='stm run hide_run'>198</p>
<p class='stm run hide_run'>199</p>
<p class='pln'>200</p>
<p class='stm run hide_run'>201</p>
<p class='stm run hide_run'>202</p>
<p class='stm run hide_run'>203</p>
<p class='pln'>204</p>
<p class='stm run hide_run'>205</p>
<p class='pln'>206</p>
<p class='stm run hide_run'>207</p>
<p class='stm run hide_run'>208</p>
<p class='stm run hide_run'>209</p>
<p class='stm run hide_run'>210</p>
<p class='stm run hide_run'>211</p>
<p class='stm mis'>212</p>
<p class='pln'>213</p>
<p class='stm run hide_run'>214</p>
<p class='pln'>215</p>
<p class='stm run hide_run'>216</p>
<p class='stm run hide_run'>217</p>
<p class='stm run hide_run'>218</p>
<p class='pln'>219</p>
<p class='stm run hide_run'>220</p>
<p class='stm run hide_run'>221</p>
<p class='stm run hide_run'>222</p>
<p class='pln'>223</p>
<p class='stm run hide_run'>224</p>
<p class='stm run hide_run'>225</p>
<p class='stm run hide_run'>226</p>
<p class='pln'>227</p>
<p class='stm run hide_run'>228</p>
<p class='pln'>229</p>
<p class='stm run hide_run'>230</p>
<p class='stm run hide_run'>231</p>
<p class='stm run hide_run'>232</p>
<p class='stm run hide_run'>233</p>
<p class='stm run hide_run'>234</p>
<p class='stm mis'>235</p>
<p class='pln'>236</p>
<p class='stm run hide_run'>237</p>
<p class='pln'>238</p>
<p class='stm run hide_run'>239</p>
<p class='stm run hide_run'>240</p>
<p class='stm run hide_run'>241</p>
<p class='pln'>242</p>
<p class='stm run hide_run'>243</p>
<p class='stm run hide_run'>244</p>
<p class='stm run hide_run'>245</p>
<p class='pln'>246</p>
<p class='stm run hide_run'>247</p>
<p class='stm run hide_run'>248</p>
<p class='stm run hide_run'>249</p>
<p class='pln'>250</p>
<p class='stm run hide_run'>251</p>
<p class='pln'>252</p>
<p class='stm run hide_run'>253</p>
<p class='stm run hide_run'>254</p>
<p class='stm run hide_run'>255</p>
<p class='stm run hide_run'>256</p>
<p class='stm run hide_run'>257</p>
<p class='stm mis'>258</p>
<p class='pln'>259</p>
<p class='stm run hide_run'>260</p>
<p class='pln'>261</p>
<p class='stm run hide_run'>262</p>
<p class='stm run hide_run'>263</p>
<p class='stm run hide_run'>264</p>
<p class='stm run hide_run'>265</p>
<p class='stm run hide_run'>266</p>
<p class='stm mis'>267</p>
<p class='pln'>268</p>
<p class='stm run hide_run'>269</p>
<p class='pln'>270</p>
<p class='stm run hide_run'>271</p>
<p class='stm run hide_run'>272</p>
<p class='stm run hide_run'>273</p>
<p class='pln'>274</p>
<p class='stm run hide_run'>275</p>
<p class='stm run hide_run'>276</p>
<p class='stm run hide_run'>277</p>
<p class='pln'>278</p>
<p class='stm run hide_run'>279</p>
<p class='stm run hide_run'>280</p>
<p class='stm run hide_run'>281</p>
<p class='pln'>282</p>
<p class='stm run hide_run'>283</p>
<p class='pln'>284</p>
<p class='stm run hide_run'>285</p>
<p class='stm run hide_run'>286</p>
<p class='stm run hide_run'>287</p>
<p class='stm run hide_run'>288</p>
<p class='stm run hide_run'>289</p>
<p class='stm mis'>290</p>
<p class='pln'>291</p>
<p class='stm run hide_run'>292</p>
<p class='pln'>293</p>
<p class='stm run hide_run'>294</p>
<p class='stm run hide_run'>295</p>
<p class='stm run hide_run'>296</p>
<p class='stm run hide_run'>297</p>
<p class='stm run hide_run'>298</p>
<p class='stm mis'>299</p>
<p class='pln'>300</p>
<p class='stm run hide_run'>301</p>
<p class='pln'>302</p>
<p class='stm run hide_run'>303</p>
<p class='stm run hide_run'>304</p>
<p class='pln'>305</p>
<p class='stm run hide_run'>306</p>
<p class='stm run hide_run'>307</p>
<p class='pln'>308</p>
<p class='stm run hide_run'>309</p>
<p class='stm run hide_run'>310</p>
<p class='stm run hide_run'>311</p>
<p class='stm run hide_run'>312</p>
<p class='stm run hide_run'>313</p>
<p class='stm run hide_run'>314</p>
<p class='stm run hide_run'>315</p>
<p class='stm run hide_run'>316</p>
<p class='pln'>317</p>
<p class='stm run hide_run'>318</p>
<p class='stm run hide_run'>319</p>
<p class='pln'>320</p>
<p class='stm run hide_run'>321</p>
<p class='stm run hide_run'>322</p>
<p class='pln'>323</p>
<p class='stm run hide_run'>324</p>
<p class='stm run hide_run'>325</p>
<p class='pln'>326</p>
<p class='stm run hide_run'>327</p>
<p class='stm run hide_run'>328</p>
<p class='pln'>329</p>
<p class='stm run hide_run'>330</p>
<p class='pln'>331</p>
<p class='stm run hide_run'>332</p>
<p class='pln'>333</p>
<p class='stm run hide_run'>334</p>
<p class='stm run hide_run'>335</p>
<p class='pln'>336</p>
<p class='stm run hide_run'>337</p>
<p class='pln'>338</p>
<p class='stm run hide_run'>339</p>
<p class='stm run hide_run'>340</p>
<p class='stm run hide_run'>341</p>
<p class='stm run hide_run'>342</p>
<p class='stm run hide_run'>343</p>
<p class='stm run hide_run'>344</p>
<p class='stm run hide_run'>345</p>
<p class='pln'>346</p>
<p class='pln'>347</p>
    
</td>
<td class='text' valign='top'>
<p class='pln'><span class='com'>#!/usr/bin/env python</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='com'># -*- coding: utf-8 -*-</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'><span class='str'>&quot;&quot;&quot;</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='str'> Modbus TestKit: Implementation of Modbus protocol in python</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='str'> (C)2009 - Luc Jean - luc.jean@gmail.com</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='str'> (C)2009 - Apidev - http://www.apidev.fr</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='str'> This is distributed under GNU LGPL license, see license.txt</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='str'>&quot;&quot;&quot;</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'><span class='key'>import</span> <span class='nam'>unittest</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'><span class='key'>import</span> <span class='nam'>modbus_tk</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'><span class='key'>import</span> <span class='nam'>modbus_tk</span><span class='op'>.</span><span class='nam'>modbus_rtu</span> <span class='key'>as</span> <span class='nam'>modbus_rtu</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'><span class='key'>import</span> <span class='nam'>threading</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'><span class='key'>import</span> <span class='nam'>struct</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'><span class='key'>import</span> <span class='nam'>logging</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'><span class='key'>import</span> <span class='nam'>modbus_tk</span><span class='op'>.</span><span class='nam'>utils</span> <span class='key'>as</span> <span class='nam'>utils</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'><span class='key'>import</span> <span class='nam'>time</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'><span class='key'>import</span> <span class='nam'>sys</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'><span class='nam'>LOGGER</span> <span class='op'>=</span> <span class='nam'>modbus_tk</span><span class='op'>.</span><span class='nam'>utils</span><span class='op'>.</span><span class='nam'>create_logger</span><span class='op'>(</span><span class='str'>&quot;udp&quot;</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'><span class='key'>class</span> <span class='nam'>TestQueriesSetupAndTeardown</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='pln'>&nbsp; &nbsp; <span class='str'>&quot;&quot;&quot;This is not a test case, but can be used by Rtu and Tcp test cases&quot;&quot;&quot;</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; <span class='key'>def</span> <span class='nam'>setUp</span><span class='op'>(</span><span class='nam'>self</span><span class='op'>)</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>self</span><span class='op'>.</span><span class='nam'>master</span> <span class='op'>=</span> <span class='nam'>self</span><span class='op'>.</span><span class='nam'>_get_master</span><span class='op'>(</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>self</span><span class='op'>.</span><span class='nam'>server</span> <span class='op'>=</span> <span class='nam'>self</span><span class='op'>.</span><span class='nam'>_get_server</span><span class='op'>(</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>self</span><span class='op'>.</span><span class='nam'>slave1</span> <span class='op'>=</span> <span class='nam'>self</span><span class='op'>.</span><span class='nam'>server</span><span class='op'>.</span><span class='nam'>add_slave</span><span class='op'>(</span><span class='num'>1</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>self</span><span class='op'>.</span><span class='nam'>slave1</span><span class='op'>.</span><span class='nam'>add_block</span><span class='op'>(</span><span class='str'>&quot;hr0-100&quot;</span><span class='op'>,</span> <span class='nam'>modbus_tk</span><span class='op'>.</span><span class='nam'>defines</span><span class='op'>.</span><span class='nam'>HOLDING_REGISTERS</span><span class='op'>,</span> <span class='num'>0</span><span class='op'>,</span> <span class='num'>100</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>self</span><span class='op'>.</span><span class='nam'>slave1</span><span class='op'>.</span><span class='nam'>add_block</span><span class='op'>(</span><span class='str'>&quot;hr100-100&quot;</span><span class='op'>,</span> <span class='nam'>modbus_tk</span><span class='op'>.</span><span class='nam'>defines</span><span class='op'>.</span><span class='nam'>HOLDING_REGISTERS</span><span class='op'>,</span> <span class='num'>100</span><span class='op'>,</span> <span class='num'>200</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>self</span><span class='op'>.</span><span class='nam'>slave1</span><span class='op'>.</span><span class='nam'>add_block</span><span class='op'>(</span><span class='str'>&quot;ai100-50&quot;</span><span class='op'>,</span> <span class='nam'>modbus_tk</span><span class='op'>.</span><span class='nam'>defines</span><span class='op'>.</span><span class='nam'>ANALOG_INPUTS</span><span class='op'>,</span> <span class='num'>100</span><span class='op'>,</span> <span class='num'>150</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>self</span><span class='op'>.</span><span class='nam'>slave1</span><span class='op'>.</span><span class='nam'>add_block</span><span class='op'>(</span><span class='str'>&quot;c0-100&quot;</span><span class='op'>,</span> <span class='nam'>modbus_tk</span><span class='op'>.</span><span class='nam'>defines</span><span class='op'>.</span><span class='nam'>COILS</span><span class='op'>,</span> <span class='num'>0</span><span class='op'>,</span> <span class='num'>100</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>self</span><span class='op'>.</span><span class='nam'>slave1</span><span class='op'>.</span><span class='nam'>add_block</span><span class='op'>(</span><span class='str'>&quot;di100-1&quot;</span><span class='op'>,</span> <span class='nam'>modbus_tk</span><span class='op'>.</span><span class='nam'>defines</span><span class='op'>.</span><span class='nam'>DISCRETE_INPUTS</span><span class='op'>,</span> <span class='num'>100</span><span class='op'>,</span> <span class='num'>1</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>self</span><span class='op'>.</span><span class='nam'>slave1</span><span class='op'>.</span><span class='nam'>add_block</span><span class='op'>(</span><span class='str'>&quot;di200-10&quot;</span><span class='op'>,</span> <span class='nam'>modbus_tk</span><span class='op'>.</span><span class='nam'>defines</span><span class='op'>.</span><span class='nam'>DISCRETE_INPUTS</span><span class='op'>,</span> <span class='num'>200</span><span class='op'>,</span> <span class='num'>10</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>self</span><span class='op'>.</span><span class='nam'>slave1</span><span class='op'>.</span><span class='nam'>add_block</span><span class='op'>(</span><span class='str'>&quot;hr1000-1500&quot;</span><span class='op'>,</span> <span class='nam'>modbus_tk</span><span class='op'>.</span><span class='nam'>defines</span><span class='op'>.</span><span class='nam'>HOLDING_REGISTERS</span><span class='op'>,</span> <span class='num'>1000</span><span class='op'>,</span> <span class='num'>500</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>self</span><span class='op'>.</span><span class='nam'>slave1</span><span class='op'>.</span><span class='nam'>add_block</span><span class='op'>(</span><span class='str'>&quot;c1000-4000&quot;</span><span class='op'>,</span> <span class='nam'>modbus_tk</span><span class='op'>.</span><span class='nam'>defines</span><span class='op'>.</span><span class='nam'>COILS</span><span class='op'>,</span> <span class='num'>1000</span><span class='op'>,</span> <span class='num'>3000</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>self</span><span class='op'>.</span><span class='nam'>slave5</span> <span class='op'>=</span> <span class='nam'>self</span><span class='op'>.</span><span class='nam'>server</span><span class='op'>.</span><span class='nam'>add_slave</span><span class='op'>(</span><span class='num'>5</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>self</span><span class='op'>.</span><span class='nam'>slave5</span><span class='op'>.</span><span class='nam'>add_block</span><span class='op'>(</span><span class='str'>&quot;hr0-100&quot;</span><span class='op'>,</span> <span class='nam'>modbus_tk</span><span class='op'>.</span><span class='nam'>defines</span><span class='op'>.</span><span class='nam'>HOLDING_REGISTERS</span><span class='op'>,</span> <span class='num'>300</span><span class='op'>,</span> <span class='num'>20</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>self</span><span class='op'>.</span><span class='nam'>server</span><span class='op'>.</span><span class='nam'>start</span><span class='op'>(</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>time</span><span class='op'>.</span><span class='nam'>sleep</span><span class='op'>(</span><span class='num'>0.1</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>self</span><span class='op'>.</span><span class='nam'>master</span><span class='op'>.</span><span class='nam'>set_timeout</span><span class='op'>(</span><span class='num'>1.0</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>self</span><span class='op'>.</span><span class='nam'>master</span><span class='op'>.</span><span class='nam'>open</span><span class='op'>(</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; <span class='key'>def</span> <span class='nam'>tearDown</span><span class='op'>(</span><span class='nam'>self</span><span class='op'>)</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>self</span><span class='op'>.</span><span class='nam'>master</span><span class='op'>.</span><span class='nam'>close</span><span class='op'>(</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>self</span><span class='op'>.</span><span class='nam'>server</span><span class='op'>.</span><span class='nam'>stop</span><span class='op'>(</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'><span class='key'>class</span> <span class='nam'>TestQueries</span><span class='op'>(</span><span class='nam'>TestQueriesSetupAndTeardown</span><span class='op'>)</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='pln'>&nbsp; &nbsp; <span class='str'>&quot;&quot;&quot;This is not a test case, but can be used by Rtu and Tcp test cases&quot;&quot;&quot;</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='pln'>&nbsp; &nbsp; <span class='str'>&quot;&quot;&quot;Test the modbus protocol&quot;&quot;&quot;</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; <span class='key'>def</span> <span class='nam'>testReadHoldingRegisters</span><span class='op'>(</span><span class='nam'>self</span><span class='op'>)</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='pln'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='str'>&quot;&quot;&quot;set the values of holding registers check that the values are read correctly&quot;&quot;&quot;</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>self</span><span class='op'>.</span><span class='nam'>slave1</span><span class='op'>.</span><span class='nam'>set_values</span><span class='op'>(</span><span class='str'>&quot;hr0-100&quot;</span><span class='op'>,</span> <span class='num'>0</span><span class='op'>,</span> <span class='nam'>range</span><span class='op'>(</span><span class='num'>100</span><span class='op'>)</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>result</span> <span class='op'>=</span> <span class='nam'>self</span><span class='op'>.</span><span class='nam'>master</span><span class='op'>.</span><span class='nam'>execute</span><span class='op'>(</span><span class='num'>1</span><span class='op'>,</span> <span class='nam'>modbus_tk</span><span class='op'>.</span><span class='nam'>defines</span><span class='op'>.</span><span class='nam'>READ_HOLDING_REGISTERS</span><span class='op'>,</span> <span class='num'>0</span><span class='op'>,</span> <span class='num'>100</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>self</span><span class='op'>.</span><span class='nam'>assertEqual</span><span class='op'>(</span><span class='nam'>tuple</span><span class='op'>(</span><span class='nam'>range</span><span class='op'>(</span><span class='num'>100</span><span class='op'>)</span><span class='op'>)</span><span class='op'>,</span> <span class='nam'>result</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>self</span><span class='op'>.</span><span class='nam'>slave1</span><span class='op'>.</span><span class='nam'>set_values</span><span class='op'>(</span><span class='str'>&quot;hr1000-1500&quot;</span><span class='op'>,</span> <span class='num'>1000</span><span class='op'>,</span> <span class='nam'>range</span><span class='op'>(</span><span class='num'>125</span><span class='op'>)</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>result</span> <span class='op'>=</span> <span class='nam'>self</span><span class='op'>.</span><span class='nam'>master</span><span class='op'>.</span><span class='nam'>execute</span><span class='op'>(</span><span class='num'>1</span><span class='op'>,</span> <span class='nam'>modbus_tk</span><span class='op'>.</span><span class='nam'>defines</span><span class='op'>.</span><span class='nam'>READ_HOLDING_REGISTERS</span><span class='op'>,</span> <span class='num'>1000</span><span class='op'>,</span> <span class='num'>125</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>self</span><span class='op'>.</span><span class='nam'>assertEqual</span><span class='op'>(</span><span class='nam'>tuple</span><span class='op'>(</span><span class='nam'>range</span><span class='op'>(</span><span class='num'>125</span><span class='op'>)</span><span class='op'>)</span><span class='op'>,</span> <span class='nam'>result</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; <span class='key'>def</span> <span class='nam'>testRead100HoldingRegistersOn2Blocks</span><span class='op'>(</span><span class='nam'>self</span><span class='op'>)</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='pln'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='str'>&quot;&quot;&quot;check that an error is raised where reading on 2 consecutive blocks&quot;&quot;&quot;</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>try</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>self</span><span class='op'>.</span><span class='nam'>master</span><span class='op'>.</span><span class='nam'>execute</span><span class='op'>(</span><span class='num'>1</span><span class='op'>,</span> <span class='nam'>modbus_tk</span><span class='op'>.</span><span class='nam'>defines</span><span class='op'>.</span><span class='nam'>READ_HOLDING_REGISTERS</span><span class='op'>,</span> <span class='num'>50</span><span class='op'>,</span> <span class='num'>100</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>except</span> <span class='nam'>modbus_tk</span><span class='op'>.</span><span class='nam'>modbus</span><span class='op'>.</span><span class='nam'>ModbusError</span><span class='op'>,</span> <span class='nam'>ex</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>self</span><span class='op'>.</span><span class='nam'>assertEqual</span><span class='op'>(</span><span class='nam'>ex</span><span class='op'>.</span><span class='nam'>get_exception_code</span><span class='op'>(</span><span class='op'>)</span><span class='op'>,</span> <span class='num'>2</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>return</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>self</span><span class='op'>.</span><span class='nam'>assert_</span><span class='op'>(</span><span class='nam'>False</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; <span class='key'>def</span> <span class='nam'>testRead5HoldingRegisters</span><span class='op'>(</span><span class='nam'>self</span><span class='op'>)</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='pln'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='str'>&quot;&quot;&quot;set the values of 3 registers and let&#39;s the master reading 5 values&quot;&quot;&quot;</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>self</span><span class='op'>.</span><span class='nam'>slave1</span><span class='op'>.</span><span class='nam'>set_values</span><span class='op'>(</span><span class='str'>&quot;hr0-100&quot;</span><span class='op'>,</span> <span class='num'>1</span><span class='op'>,</span> <span class='op'>[</span><span class='num'>2</span><span class='op'>,</span> <span class='num'>2</span><span class='op'>,</span> <span class='num'>2</span><span class='op'>]</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>result</span> <span class='op'>=</span> <span class='nam'>self</span><span class='op'>.</span><span class='nam'>master</span><span class='op'>.</span><span class='nam'>execute</span><span class='op'>(</span><span class='num'>1</span><span class='op'>,</span> <span class='nam'>modbus_tk</span><span class='op'>.</span><span class='nam'>defines</span><span class='op'>.</span><span class='nam'>READ_HOLDING_REGISTERS</span><span class='op'>,</span> <span class='num'>0</span><span class='op'>,</span> <span class='num'>5</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>self</span><span class='op'>.</span><span class='nam'>assertEqual</span><span class='op'>(</span><span class='op'>(</span><span class='num'>0</span><span class='op'>,</span> <span class='num'>2</span><span class='op'>,</span> <span class='num'>2</span><span class='op'>,</span> <span class='num'>2</span><span class='op'>,</span> <span class='num'>0</span><span class='op'>)</span><span class='op'>,</span> <span class='nam'>result</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; <span class='key'>def</span> <span class='nam'>testReadOneHoldingRegisters</span><span class='op'>(</span><span class='nam'>self</span><span class='op'>)</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='pln'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='str'>&quot;&quot;&quot;set the values of 3 registers and let&#39;s the master reading 5 values&quot;&quot;&quot;</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>self</span><span class='op'>.</span><span class='nam'>slave1</span><span class='op'>.</span><span class='nam'>set_values</span><span class='op'>(</span><span class='str'>&quot;hr0-100&quot;</span><span class='op'>,</span> <span class='num'>6</span><span class='op'>,</span> <span class='num'>4</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>result</span> <span class='op'>=</span> <span class='nam'>self</span><span class='op'>.</span><span class='nam'>master</span><span class='op'>.</span><span class='nam'>execute</span><span class='op'>(</span><span class='num'>1</span><span class='op'>,</span> <span class='nam'>modbus_tk</span><span class='op'>.</span><span class='nam'>defines</span><span class='op'>.</span><span class='nam'>READ_HOLDING_REGISTERS</span><span class='op'>,</span> <span class='num'>6</span><span class='op'>,</span> <span class='num'>1</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>self</span><span class='op'>.</span><span class='nam'>assertEqual</span><span class='op'>(</span><span class='op'>(</span><span class='num'>4</span><span class='op'>,</span> <span class='op'>)</span><span class='op'>,</span> <span class='nam'>result</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; <span class='key'>def</span> <span class='nam'>testReadHoldingRegistersOnSlave5</span><span class='op'>(</span><span class='nam'>self</span><span class='op'>)</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='pln'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='str'>&quot;&quot;&quot;set and read the values of some registers on slave 5&quot;&quot;&quot;</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>self</span><span class='op'>.</span><span class='nam'>slave5</span><span class='op'>.</span><span class='nam'>set_values</span><span class='op'>(</span><span class='str'>&quot;hr0-100&quot;</span><span class='op'>,</span> <span class='num'>310</span><span class='op'>,</span> <span class='op'>(</span><span class='num'>1</span><span class='op'>,</span> <span class='num'>2</span><span class='op'>,</span> <span class='num'>3</span><span class='op'>)</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>result</span> <span class='op'>=</span> <span class='nam'>self</span><span class='op'>.</span><span class='nam'>master</span><span class='op'>.</span><span class='nam'>execute</span><span class='op'>(</span><span class='num'>5</span><span class='op'>,</span> <span class='nam'>modbus_tk</span><span class='op'>.</span><span class='nam'>defines</span><span class='op'>.</span><span class='nam'>READ_HOLDING_REGISTERS</span><span class='op'>,</span> <span class='num'>308</span><span class='op'>,</span> <span class='num'>10</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>self</span><span class='op'>.</span><span class='nam'>assertEqual</span><span class='op'>(</span><span class='op'>(</span><span class='num'>0</span><span class='op'>,</span> <span class='num'>0</span><span class='op'>,</span> <span class='num'>1</span><span class='op'>,</span> <span class='num'>2</span><span class='op'>,</span> <span class='num'>3</span><span class='op'>,</span> <span class='num'>0</span><span class='op'>,</span> <span class='num'>0</span><span class='op'>,</span> <span class='num'>0</span><span class='op'>,</span> <span class='num'>0</span><span class='op'>,</span> <span class='num'>0</span><span class='op'>)</span><span class='op'>,</span> <span class='nam'>result</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; <span class='key'>def</span> <span class='nam'>testReadHoldingRegistersOutOfBlock</span><span class='op'>(</span><span class='nam'>self</span><span class='op'>)</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='pln'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='str'>&quot;&quot;&quot;read out of block and make sure that the correct exception is raised&quot;&quot;&quot;</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>self</span><span class='op'>.</span><span class='nam'>assertRaises</span><span class='op'>(</span><span class='nam'>modbus_tk</span><span class='op'>.</span><span class='nam'>modbus</span><span class='op'>.</span><span class='nam'>ModbusError</span><span class='op'>,</span> <span class='nam'>self</span><span class='op'>.</span><span class='nam'>master</span><span class='op'>.</span><span class='nam'>execute</span><span class='op'>,</span> <span class='num'>1</span><span class='op'>,</span> <span class='nam'>modbus_tk</span><span class='op'>.</span><span class='nam'>defines</span><span class='op'>.</span><span class='nam'>READ_HOLDING_REGISTERS</span><span class='op'>,</span> <span class='num'>300</span><span class='op'>,</span> <span class='num'>10</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>try</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>self</span><span class='op'>.</span><span class='nam'>master</span><span class='op'>.</span><span class='nam'>execute</span><span class='op'>(</span><span class='num'>1</span><span class='op'>,</span> <span class='nam'>modbus_tk</span><span class='op'>.</span><span class='nam'>defines</span><span class='op'>.</span><span class='nam'>READ_HOLDING_REGISTERS</span><span class='op'>,</span> <span class='num'>300</span><span class='op'>,</span> <span class='num'>10</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>except</span> <span class='nam'>modbus_tk</span><span class='op'>.</span><span class='nam'>modbus</span><span class='op'>.</span><span class='nam'>ModbusError</span><span class='op'>,</span> <span class='nam'>ex</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>self</span><span class='op'>.</span><span class='nam'>assertEqual</span><span class='op'>(</span><span class='nam'>ex</span><span class='op'>.</span><span class='nam'>get_exception_code</span><span class='op'>(</span><span class='op'>)</span><span class='op'>,</span> <span class='num'>2</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>return</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>self</span><span class='op'>.</span><span class='nam'>assert_</span><span class='op'>(</span><span class='nam'>False</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; <span class='key'>def</span> <span class='nam'>testReadTooManyHoldingRegisters</span><span class='op'>(</span><span class='nam'>self</span><span class='op'>)</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='pln'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='str'>&quot;&quot;&quot;check than an error is raised when reading too many holding registers&quot;&quot;&quot;</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>try</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>self</span><span class='op'>.</span><span class='nam'>master</span><span class='op'>.</span><span class='nam'>execute</span><span class='op'>(</span><span class='num'>1</span><span class='op'>,</span> <span class='nam'>modbus_tk</span><span class='op'>.</span><span class='nam'>defines</span><span class='op'>.</span><span class='nam'>READ_HOLDING_REGISTERS</span><span class='op'>,</span> <span class='num'>1000</span><span class='op'>,</span> <span class='num'>126</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>except</span> <span class='nam'>modbus_tk</span><span class='op'>.</span><span class='nam'>modbus</span><span class='op'>.</span><span class='nam'>ModbusError</span><span class='op'>,</span> <span class='nam'>ex</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>self</span><span class='op'>.</span><span class='nam'>assertEqual</span><span class='op'>(</span><span class='nam'>ex</span><span class='op'>.</span><span class='nam'>get_exception_code</span><span class='op'>(</span><span class='op'>)</span><span class='op'>,</span> <span class='num'>3</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>return</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>self</span><span class='op'>.</span><span class='nam'>assert_</span><span class='op'>(</span><span class='nam'>False</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; <span class='key'>def</span> <span class='nam'>testReadAnalogInputs</span><span class='op'>(</span><span class='nam'>self</span><span class='op'>)</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='pln'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='str'>&quot;&quot;&quot;Test that response for read analog inputs function is ok&quot;&quot;&quot;</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>self</span><span class='op'>.</span><span class='nam'>slave1</span><span class='op'>.</span><span class='nam'>set_values</span><span class='op'>(</span><span class='str'>&quot;ai100-50&quot;</span><span class='op'>,</span> <span class='num'>120</span><span class='op'>,</span> <span class='nam'>range</span><span class='op'>(</span><span class='num'>10</span><span class='op'>)</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>result</span> <span class='op'>=</span> <span class='nam'>self</span><span class='op'>.</span><span class='nam'>master</span><span class='op'>.</span><span class='nam'>execute</span><span class='op'>(</span><span class='num'>1</span><span class='op'>,</span> <span class='nam'>modbus_tk</span><span class='op'>.</span><span class='nam'>defines</span><span class='op'>.</span><span class='nam'>READ_INPUT_REGISTERS</span><span class='op'>,</span> <span class='num'>120</span><span class='op'>,</span> <span class='num'>10</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>self</span><span class='op'>.</span><span class='nam'>assertEqual</span><span class='op'>(</span><span class='nam'>tuple</span><span class='op'>(</span><span class='nam'>range</span><span class='op'>(</span><span class='num'>10</span><span class='op'>)</span><span class='op'>)</span><span class='op'>,</span> <span class='nam'>result</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>result</span> <span class='op'>=</span> <span class='nam'>self</span><span class='op'>.</span><span class='nam'>master</span><span class='op'>.</span><span class='nam'>execute</span><span class='op'>(</span><span class='num'>1</span><span class='op'>,</span> <span class='nam'>modbus_tk</span><span class='op'>.</span><span class='nam'>defines</span><span class='op'>.</span><span class='nam'>READ_INPUT_REGISTERS</span><span class='op'>,</span> <span class='num'>120</span><span class='op'>,</span> <span class='num'>1</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>self</span><span class='op'>.</span><span class='nam'>assertEqual</span><span class='op'>(</span><span class='op'>(</span><span class='num'>0</span><span class='op'>,</span><span class='op'>)</span><span class='op'>,</span> <span class='nam'>result</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; <span class='key'>def</span> <span class='nam'>testReadCoils</span><span class='op'>(</span><span class='nam'>self</span><span class='op'>)</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='pln'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='str'>&quot;&quot;&quot;Test that response for read coils function is ok&quot;&quot;&quot;</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>self</span><span class='op'>.</span><span class='nam'>slave1</span><span class='op'>.</span><span class='nam'>set_values</span><span class='op'>(</span><span class='str'>&quot;c0-100&quot;</span><span class='op'>,</span> <span class='num'>0</span><span class='op'>,</span> <span class='op'>[</span><span class='num'>0</span><span class='op'>,</span> <span class='num'>1</span><span class='op'>,</span> <span class='num'>1</span><span class='op'>]</span><span class='op'>+</span><span class='op'>[</span><span class='num'>0</span><span class='op'>,</span> <span class='num'>1</span><span class='op'>]</span><span class='op'>*</span><span class='num'>20</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>result</span> <span class='op'>=</span> <span class='nam'>self</span><span class='op'>.</span><span class='nam'>master</span><span class='op'>.</span><span class='nam'>execute</span><span class='op'>(</span><span class='num'>1</span><span class='op'>,</span> <span class='nam'>modbus_tk</span><span class='op'>.</span><span class='nam'>defines</span><span class='op'>.</span><span class='nam'>READ_COILS</span><span class='op'>,</span> <span class='num'>0</span><span class='op'>,</span> <span class='num'>1</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>self</span><span class='op'>.</span><span class='nam'>assertEqual</span><span class='op'>(</span><span class='op'>(</span><span class='num'>0</span><span class='op'>,</span><span class='op'>)</span><span class='op'>,</span> <span class='nam'>result</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>result</span> <span class='op'>=</span> <span class='nam'>self</span><span class='op'>.</span><span class='nam'>master</span><span class='op'>.</span><span class='nam'>execute</span><span class='op'>(</span><span class='num'>1</span><span class='op'>,</span> <span class='nam'>modbus_tk</span><span class='op'>.</span><span class='nam'>defines</span><span class='op'>.</span><span class='nam'>READ_COILS</span><span class='op'>,</span> <span class='num'>0</span><span class='op'>,</span> <span class='num'>3</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>self</span><span class='op'>.</span><span class='nam'>assertEqual</span><span class='op'>(</span><span class='op'>(</span><span class='num'>0</span><span class='op'>,</span><span class='num'>1</span><span class='op'>,</span><span class='num'>1</span><span class='op'>)</span><span class='op'>,</span> <span class='nam'>result</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>result</span> <span class='op'>=</span> <span class='nam'>self</span><span class='op'>.</span><span class='nam'>master</span><span class='op'>.</span><span class='nam'>execute</span><span class='op'>(</span><span class='num'>1</span><span class='op'>,</span> <span class='nam'>modbus_tk</span><span class='op'>.</span><span class='nam'>defines</span><span class='op'>.</span><span class='nam'>READ_COILS</span><span class='op'>,</span> <span class='num'>0</span><span class='op'>,</span> <span class='num'>8</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>self</span><span class='op'>.</span><span class='nam'>assertEqual</span><span class='op'>(</span><span class='nam'>tuple</span><span class='op'>(</span><span class='op'>[</span><span class='num'>0</span><span class='op'>,</span> <span class='num'>1</span><span class='op'>,</span> <span class='num'>1</span><span class='op'>]</span><span class='op'>+</span><span class='op'>[</span><span class='num'>0</span><span class='op'>,</span><span class='num'>1</span><span class='op'>]</span><span class='op'>*</span><span class='num'>2</span><span class='op'>+</span><span class='op'>[</span><span class='num'>0</span><span class='op'>]</span><span class='op'>)</span><span class='op'>,</span> <span class='nam'>result</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>result</span> <span class='op'>=</span> <span class='nam'>self</span><span class='op'>.</span><span class='nam'>master</span><span class='op'>.</span><span class='nam'>execute</span><span class='op'>(</span><span class='num'>1</span><span class='op'>,</span> <span class='nam'>modbus_tk</span><span class='op'>.</span><span class='nam'>defines</span><span class='op'>.</span><span class='nam'>READ_COILS</span><span class='op'>,</span> <span class='num'>0</span><span class='op'>,</span> <span class='num'>9</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>self</span><span class='op'>.</span><span class='nam'>assertEqual</span><span class='op'>(</span><span class='nam'>tuple</span><span class='op'>(</span><span class='op'>[</span><span class='num'>0</span><span class='op'>,</span> <span class='num'>1</span><span class='op'>,</span> <span class='num'>1</span><span class='op'>]</span><span class='op'>+</span><span class='op'>[</span><span class='num'>0</span><span class='op'>,</span><span class='num'>1</span><span class='op'>]</span><span class='op'>*</span><span class='num'>3</span><span class='op'>)</span><span class='op'>,</span> <span class='nam'>result</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>result</span> <span class='op'>=</span> <span class='nam'>self</span><span class='op'>.</span><span class='nam'>master</span><span class='op'>.</span><span class='nam'>execute</span><span class='op'>(</span><span class='num'>1</span><span class='op'>,</span> <span class='nam'>modbus_tk</span><span class='op'>.</span><span class='nam'>defines</span><span class='op'>.</span><span class='nam'>READ_COILS</span><span class='op'>,</span> <span class='num'>0</span><span class='op'>,</span> <span class='num'>20</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>self</span><span class='op'>.</span><span class='nam'>assertEqual</span><span class='op'>(</span><span class='nam'>tuple</span><span class='op'>(</span><span class='op'>[</span><span class='num'>0</span><span class='op'>,</span> <span class='num'>1</span><span class='op'>,</span> <span class='num'>1</span><span class='op'>]</span><span class='op'>+</span><span class='op'>[</span><span class='num'>0</span><span class='op'>,</span><span class='num'>1</span><span class='op'>]</span><span class='op'>*</span><span class='num'>8</span><span class='op'>+</span><span class='op'>[</span><span class='num'>0</span><span class='op'>]</span><span class='op'>)</span><span class='op'>,</span> <span class='nam'>result</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>result</span> <span class='op'>=</span> <span class='nam'>self</span><span class='op'>.</span><span class='nam'>master</span><span class='op'>.</span><span class='nam'>execute</span><span class='op'>(</span><span class='num'>1</span><span class='op'>,</span> <span class='nam'>modbus_tk</span><span class='op'>.</span><span class='nam'>defines</span><span class='op'>.</span><span class='nam'>READ_COILS</span><span class='op'>,</span> <span class='num'>0</span><span class='op'>,</span> <span class='num'>21</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>self</span><span class='op'>.</span><span class='nam'>assertEqual</span><span class='op'>(</span><span class='nam'>tuple</span><span class='op'>(</span><span class='op'>[</span><span class='num'>0</span><span class='op'>,</span> <span class='num'>1</span><span class='op'>,</span> <span class='num'>1</span><span class='op'>]</span><span class='op'>+</span><span class='op'>[</span><span class='num'>0</span><span class='op'>,</span><span class='num'>1</span><span class='op'>]</span><span class='op'>*</span><span class='num'>9</span><span class='op'>)</span><span class='op'>,</span> <span class='nam'>result</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; <span class='key'>def</span> <span class='nam'>testReadManyCoils</span><span class='op'>(</span><span class='nam'>self</span><span class='op'>)</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='pln'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='str'>&quot;&quot;&quot;Test that response for read many coils function is ok&quot;&quot;&quot;</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>self</span><span class='op'>.</span><span class='nam'>slave1</span><span class='op'>.</span><span class='nam'>set_values</span><span class='op'>(</span><span class='str'>&quot;c1000-4000&quot;</span><span class='op'>,</span> <span class='num'>1000</span><span class='op'>,</span> <span class='nam'>tuple</span><span class='op'>(</span><span class='op'>[</span><span class='num'>0</span><span class='op'>,</span><span class='num'>1</span><span class='op'>]</span><span class='op'>*</span><span class='num'>1000</span><span class='op'>)</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>result</span> <span class='op'>=</span> <span class='nam'>self</span><span class='op'>.</span><span class='nam'>master</span><span class='op'>.</span><span class='nam'>execute</span><span class='op'>(</span><span class='num'>1</span><span class='op'>,</span> <span class='nam'>modbus_tk</span><span class='op'>.</span><span class='nam'>defines</span><span class='op'>.</span><span class='nam'>READ_COILS</span><span class='op'>,</span> <span class='num'>1000</span><span class='op'>,</span> <span class='num'>1</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>self</span><span class='op'>.</span><span class='nam'>assertEqual</span><span class='op'>(</span><span class='num'>1</span><span class='op'>,</span> <span class='nam'>len</span><span class='op'>(</span><span class='nam'>result</span><span class='op'>)</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>self</span><span class='op'>.</span><span class='nam'>assertEqual</span><span class='op'>(</span><span class='op'>(</span><span class='num'>0</span><span class='op'>,</span><span class='op'>)</span><span class='op'>,</span> <span class='nam'>result</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>result</span> <span class='op'>=</span> <span class='nam'>self</span><span class='op'>.</span><span class='nam'>master</span><span class='op'>.</span><span class='nam'>execute</span><span class='op'>(</span><span class='num'>1</span><span class='op'>,</span> <span class='nam'>modbus_tk</span><span class='op'>.</span><span class='nam'>defines</span><span class='op'>.</span><span class='nam'>READ_COILS</span><span class='op'>,</span> <span class='num'>1000</span><span class='op'>,</span> <span class='num'>8</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>self</span><span class='op'>.</span><span class='nam'>assertEqual</span><span class='op'>(</span><span class='num'>8</span><span class='op'>,</span> <span class='nam'>len</span><span class='op'>(</span><span class='nam'>result</span><span class='op'>)</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>self</span><span class='op'>.</span><span class='nam'>assertEqual</span><span class='op'>(</span><span class='nam'>tuple</span><span class='op'>(</span><span class='op'>[</span><span class='num'>0</span><span class='op'>,</span><span class='num'>1</span><span class='op'>]</span><span class='op'>*</span><span class='num'>4</span><span class='op'>)</span><span class='op'>,</span> <span class='nam'>result</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>result</span> <span class='op'>=</span> <span class='nam'>self</span><span class='op'>.</span><span class='nam'>master</span><span class='op'>.</span><span class='nam'>execute</span><span class='op'>(</span><span class='num'>1</span><span class='op'>,</span> <span class='nam'>modbus_tk</span><span class='op'>.</span><span class='nam'>defines</span><span class='op'>.</span><span class='nam'>READ_COILS</span><span class='op'>,</span> <span class='num'>1000</span><span class='op'>,</span> <span class='num'>1999</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>self</span><span class='op'>.</span><span class='nam'>assertEqual</span><span class='op'>(</span><span class='num'>1999</span><span class='op'>,</span> <span class='nam'>len</span><span class='op'>(</span><span class='nam'>result</span><span class='op'>)</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>self</span><span class='op'>.</span><span class='nam'>assertEqual</span><span class='op'>(</span><span class='nam'>tuple</span><span class='op'>(</span><span class='op'>[</span><span class='num'>0</span><span class='op'>,</span><span class='num'>1</span><span class='op'>]</span><span class='op'>*</span><span class='num'>999</span><span class='op'>+</span><span class='op'>[</span><span class='num'>0</span><span class='op'>]</span><span class='op'>)</span><span class='op'>,</span> <span class='nam'>result</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>result</span> <span class='op'>=</span> <span class='nam'>self</span><span class='op'>.</span><span class='nam'>master</span><span class='op'>.</span><span class='nam'>execute</span><span class='op'>(</span><span class='num'>1</span><span class='op'>,</span> <span class='nam'>modbus_tk</span><span class='op'>.</span><span class='nam'>defines</span><span class='op'>.</span><span class='nam'>READ_COILS</span><span class='op'>,</span> <span class='num'>1000</span><span class='op'>,</span> <span class='num'>2000</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>self</span><span class='op'>.</span><span class='nam'>assertEqual</span><span class='op'>(</span><span class='num'>2000</span><span class='op'>,</span> <span class='nam'>len</span><span class='op'>(</span><span class='nam'>result</span><span class='op'>)</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>self</span><span class='op'>.</span><span class='nam'>assertEqual</span><span class='op'>(</span><span class='nam'>tuple</span><span class='op'>(</span><span class='op'>[</span><span class='num'>0</span><span class='op'>,</span><span class='num'>1</span><span class='op'>]</span><span class='op'>*</span><span class='num'>1000</span><span class='op'>)</span><span class='op'>,</span> <span class='nam'>result</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; <span class='key'>def</span> <span class='nam'>testReadCoilsOutOfBlocks</span><span class='op'>(</span><span class='nam'>self</span><span class='op'>)</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='pln'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='str'>&quot;&quot;&quot;Test that an error is raised when reading an invalid address&quot;&quot;&quot;</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>try</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>self</span><span class='op'>.</span><span class='nam'>master</span><span class='op'>.</span><span class='nam'>execute</span><span class='op'>(</span><span class='num'>1</span><span class='op'>,</span> <span class='nam'>modbus_tk</span><span class='op'>.</span><span class='nam'>defines</span><span class='op'>.</span><span class='nam'>READ_COILS</span><span class='op'>,</span> <span class='num'>500</span><span class='op'>,</span> <span class='num'>12</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>except</span> <span class='nam'>modbus_tk</span><span class='op'>.</span><span class='nam'>modbus</span><span class='op'>.</span><span class='nam'>ModbusError</span><span class='op'>,</span> <span class='nam'>ex</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>self</span><span class='op'>.</span><span class='nam'>assertEqual</span><span class='op'>(</span><span class='nam'>ex</span><span class='op'>.</span><span class='nam'>get_exception_code</span><span class='op'>(</span><span class='op'>)</span><span class='op'>,</span> <span class='num'>2</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>return</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>self</span><span class='op'>.</span><span class='nam'>assert_</span><span class='op'>(</span><span class='nam'>False</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; <span class='key'>def</span> <span class='nam'>testReadTooManyCoils</span><span class='op'>(</span><span class='nam'>self</span><span class='op'>)</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='pln'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='str'>&quot;&quot;&quot;Test that an error is raised when too many coils are read&quot;&quot;&quot;</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>try</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>self</span><span class='op'>.</span><span class='nam'>master</span><span class='op'>.</span><span class='nam'>execute</span><span class='op'>(</span><span class='num'>1</span><span class='op'>,</span> <span class='nam'>modbus_tk</span><span class='op'>.</span><span class='nam'>defines</span><span class='op'>.</span><span class='nam'>READ_COILS</span><span class='op'>,</span> <span class='num'>1000</span><span class='op'>,</span> <span class='num'>2001</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>except</span> <span class='nam'>modbus_tk</span><span class='op'>.</span><span class='nam'>modbus</span><span class='op'>.</span><span class='nam'>ModbusError</span><span class='op'>,</span> <span class='nam'>ex</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>self</span><span class='op'>.</span><span class='nam'>assertEqual</span><span class='op'>(</span><span class='nam'>ex</span><span class='op'>.</span><span class='nam'>get_exception_code</span><span class='op'>(</span><span class='op'>)</span><span class='op'>,</span> <span class='num'>3</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>return</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>self</span><span class='op'>.</span><span class='nam'>assert_</span><span class='op'>(</span><span class='nam'>False</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; <span class='key'>def</span> <span class='nam'>testReadDiscreteInputs</span><span class='op'>(</span><span class='nam'>self</span><span class='op'>)</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='pln'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='str'>&quot;&quot;&quot;Test that response for read digital inputs function is ok&quot;&quot;&quot;</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>result</span> <span class='op'>=</span> <span class='nam'>self</span><span class='op'>.</span><span class='nam'>master</span><span class='op'>.</span><span class='nam'>execute</span><span class='op'>(</span><span class='num'>1</span><span class='op'>,</span> <span class='nam'>modbus_tk</span><span class='op'>.</span><span class='nam'>defines</span><span class='op'>.</span><span class='nam'>READ_DISCRETE_INPUTS</span><span class='op'>,</span> <span class='num'>100</span><span class='op'>,</span> <span class='num'>1</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>self</span><span class='op'>.</span><span class='nam'>assertEqual</span><span class='op'>(</span><span class='op'>(</span><span class='num'>0</span><span class='op'>,</span><span class='op'>)</span><span class='op'>,</span> <span class='nam'>result</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>self</span><span class='op'>.</span><span class='nam'>slave1</span><span class='op'>.</span><span class='nam'>set_values</span><span class='op'>(</span><span class='str'>&quot;di100-1&quot;</span><span class='op'>,</span> <span class='num'>100</span><span class='op'>,</span> <span class='num'>1</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>result</span> <span class='op'>=</span> <span class='nam'>self</span><span class='op'>.</span><span class='nam'>master</span><span class='op'>.</span><span class='nam'>execute</span><span class='op'>(</span><span class='num'>1</span><span class='op'>,</span> <span class='nam'>modbus_tk</span><span class='op'>.</span><span class='nam'>defines</span><span class='op'>.</span><span class='nam'>READ_DISCRETE_INPUTS</span><span class='op'>,</span> <span class='num'>100</span><span class='op'>,</span> <span class='num'>1</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>self</span><span class='op'>.</span><span class='nam'>assertEqual</span><span class='op'>(</span><span class='op'>(</span><span class='num'>1</span><span class='op'>,</span><span class='op'>)</span><span class='op'>,</span> <span class='nam'>result</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>self</span><span class='op'>.</span><span class='nam'>slave1</span><span class='op'>.</span><span class='nam'>set_values</span><span class='op'>(</span><span class='str'>&quot;di200-10&quot;</span><span class='op'>,</span> <span class='num'>200</span><span class='op'>,</span> <span class='nam'>range</span><span class='op'>(</span><span class='num'>8</span><span class='op'>)</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>result</span> <span class='op'>=</span> <span class='nam'>self</span><span class='op'>.</span><span class='nam'>master</span><span class='op'>.</span><span class='nam'>execute</span><span class='op'>(</span><span class='num'>1</span><span class='op'>,</span> <span class='nam'>modbus_tk</span><span class='op'>.</span><span class='nam'>defines</span><span class='op'>.</span><span class='nam'>READ_DISCRETE_INPUTS</span><span class='op'>,</span> <span class='num'>200</span><span class='op'>,</span> <span class='num'>1</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>self</span><span class='op'>.</span><span class='nam'>assertEqual</span><span class='op'>(</span><span class='op'>(</span><span class='num'>0</span><span class='op'>,</span><span class='op'>)</span><span class='op'>,</span> <span class='nam'>result</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>result</span> <span class='op'>=</span> <span class='nam'>self</span><span class='op'>.</span><span class='nam'>master</span><span class='op'>.</span><span class='nam'>execute</span><span class='op'>(</span><span class='num'>1</span><span class='op'>,</span> <span class='nam'>modbus_tk</span><span class='op'>.</span><span class='nam'>defines</span><span class='op'>.</span><span class='nam'>READ_DISCRETE_INPUTS</span><span class='op'>,</span> <span class='num'>200</span><span class='op'>,</span> <span class='num'>3</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>self</span><span class='op'>.</span><span class='nam'>assertEqual</span><span class='op'>(</span><span class='op'>(</span><span class='num'>0</span><span class='op'>,</span><span class='num'>1</span><span class='op'>,</span><span class='num'>1</span><span class='op'>)</span><span class='op'>,</span> <span class='nam'>result</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>result</span> <span class='op'>=</span> <span class='nam'>self</span><span class='op'>.</span><span class='nam'>master</span><span class='op'>.</span><span class='nam'>execute</span><span class='op'>(</span><span class='num'>1</span><span class='op'>,</span> <span class='nam'>modbus_tk</span><span class='op'>.</span><span class='nam'>defines</span><span class='op'>.</span><span class='nam'>READ_DISCRETE_INPUTS</span><span class='op'>,</span> <span class='num'>200</span><span class='op'>,</span> <span class='num'>8</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>self</span><span class='op'>.</span><span class='nam'>assertEqual</span><span class='op'>(</span><span class='nam'>tuple</span><span class='op'>(</span><span class='op'>[</span><span class='num'>0</span><span class='op'>]</span><span class='op'>+</span><span class='op'>[</span><span class='num'>1</span><span class='op'>]</span><span class='op'>*</span><span class='num'>7</span><span class='op'>)</span><span class='op'>,</span> <span class='nam'>result</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>result</span> <span class='op'>=</span> <span class='nam'>self</span><span class='op'>.</span><span class='nam'>master</span><span class='op'>.</span><span class='nam'>execute</span><span class='op'>(</span><span class='num'>1</span><span class='op'>,</span> <span class='nam'>modbus_tk</span><span class='op'>.</span><span class='nam'>defines</span><span class='op'>.</span><span class='nam'>READ_DISCRETE_INPUTS</span><span class='op'>,</span> <span class='num'>200</span><span class='op'>,</span> <span class='num'>10</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>self</span><span class='op'>.</span><span class='nam'>assertEqual</span><span class='op'>(</span><span class='nam'>tuple</span><span class='op'>(</span><span class='op'>[</span><span class='num'>0</span><span class='op'>]</span><span class='op'>+</span><span class='op'>[</span><span class='num'>1</span><span class='op'>]</span><span class='op'>*</span><span class='num'>7</span><span class='op'>+</span><span class='op'>[</span><span class='num'>0</span><span class='op'>]</span><span class='op'>*</span><span class='num'>2</span><span class='op'>)</span><span class='op'>,</span> <span class='nam'>result</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; <span class='key'>def</span> <span class='nam'>testWriteSingleRegisters</span><span class='op'>(</span><span class='nam'>self</span><span class='op'>)</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='pln'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='str'>&quot;&quot;&quot;Write the values of a single register and check that it is correctly written&quot;&quot;&quot;</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>result</span> <span class='op'>=</span> <span class='nam'>self</span><span class='op'>.</span><span class='nam'>master</span><span class='op'>.</span><span class='nam'>execute</span><span class='op'>(</span><span class='num'>1</span><span class='op'>,</span> <span class='nam'>modbus_tk</span><span class='op'>.</span><span class='nam'>defines</span><span class='op'>.</span><span class='nam'>WRITE_SINGLE_REGISTER</span><span class='op'>,</span> <span class='num'>0</span><span class='op'>,</span> <span class='nam'>output_value</span><span class='op'>=</span><span class='num'>54</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>self</span><span class='op'>.</span><span class='nam'>assertEqual</span><span class='op'>(</span><span class='op'>(</span><span class='num'>0</span><span class='op'>,</span> <span class='num'>54</span><span class='op'>)</span><span class='op'>,</span> <span class='nam'>result</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>self</span><span class='op'>.</span><span class='nam'>assertEqual</span><span class='op'>(</span><span class='op'>(</span><span class='num'>54</span><span class='op'>,</span><span class='op'>)</span><span class='op'>,</span> <span class='nam'>self</span><span class='op'>.</span><span class='nam'>slave1</span><span class='op'>.</span><span class='nam'>get_values</span><span class='op'>(</span><span class='str'>&quot;hr0-100&quot;</span><span class='op'>,</span> <span class='num'>0</span><span class='op'>,</span> <span class='num'>1</span><span class='op'>)</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>result</span> <span class='op'>=</span> <span class='nam'>self</span><span class='op'>.</span><span class='nam'>master</span><span class='op'>.</span><span class='nam'>execute</span><span class='op'>(</span><span class='num'>1</span><span class='op'>,</span> <span class='nam'>modbus_tk</span><span class='op'>.</span><span class='nam'>defines</span><span class='op'>.</span><span class='nam'>WRITE_SINGLE_REGISTER</span><span class='op'>,</span> <span class='num'>10</span><span class='op'>,</span> <span class='nam'>output_value</span><span class='op'>=</span><span class='num'>33</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>self</span><span class='op'>.</span><span class='nam'>assertEqual</span><span class='op'>(</span><span class='op'>(</span><span class='num'>10</span><span class='op'>,</span> <span class='num'>33</span><span class='op'>)</span><span class='op'>,</span> <span class='nam'>result</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>self</span><span class='op'>.</span><span class='nam'>assertEqual</span><span class='op'>(</span><span class='op'>(</span><span class='num'>33</span><span class='op'>,</span><span class='op'>)</span><span class='op'>,</span> <span class='nam'>self</span><span class='op'>.</span><span class='nam'>slave1</span><span class='op'>.</span><span class='nam'>get_values</span><span class='op'>(</span><span class='str'>&quot;hr0-100&quot;</span><span class='op'>,</span> <span class='num'>10</span><span class='op'>,</span> <span class='num'>1</span><span class='op'>)</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; <span class='key'>def</span> <span class='nam'>testWriteSingleRegistersOutOfBlocks</span><span class='op'>(</span><span class='nam'>self</span><span class='op'>)</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='pln'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='str'>&quot;&quot;&quot;Check taht an error is raised when writing a register out of block&quot;&quot;&quot;</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>try</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>self</span><span class='op'>.</span><span class='nam'>master</span><span class='op'>.</span><span class='nam'>execute</span><span class='op'>(</span><span class='num'>1</span><span class='op'>,</span> <span class='nam'>modbus_tk</span><span class='op'>.</span><span class='nam'>defines</span><span class='op'>.</span><span class='nam'>WRITE_SINGLE_REGISTER</span><span class='op'>,</span> <span class='num'>500</span><span class='op'>,</span> <span class='nam'>output_value</span><span class='op'>=</span><span class='num'>11</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>except</span> <span class='nam'>modbus_tk</span><span class='op'>.</span><span class='nam'>modbus</span><span class='op'>.</span><span class='nam'>ModbusError</span><span class='op'>,</span> <span class='nam'>ex</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>self</span><span class='op'>.</span><span class='nam'>assertEqual</span><span class='op'>(</span><span class='nam'>ex</span><span class='op'>.</span><span class='nam'>get_exception_code</span><span class='op'>(</span><span class='op'>)</span><span class='op'>,</span> <span class='num'>2</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>return</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>self</span><span class='op'>.</span><span class='nam'>assert_</span><span class='op'>(</span><span class='nam'>False</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; <span class='key'>def</span> <span class='nam'>testWriteSingleCoil</span><span class='op'>(</span><span class='nam'>self</span><span class='op'>)</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='pln'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='str'>&quot;&quot;&quot;Write the values of coils and check that it is correctly written&quot;&quot;&quot;</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>result</span> <span class='op'>=</span> <span class='nam'>self</span><span class='op'>.</span><span class='nam'>master</span><span class='op'>.</span><span class='nam'>execute</span><span class='op'>(</span><span class='num'>1</span><span class='op'>,</span> <span class='nam'>modbus_tk</span><span class='op'>.</span><span class='nam'>defines</span><span class='op'>.</span><span class='nam'>WRITE_SINGLE_COIL</span><span class='op'>,</span> <span class='num'>0</span><span class='op'>,</span> <span class='nam'>output_value</span><span class='op'>=</span><span class='num'>1</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>self</span><span class='op'>.</span><span class='nam'>assertEqual</span><span class='op'>(</span><span class='op'>(</span><span class='num'>0</span><span class='op'>,</span> <span class='nam'>int</span><span class='op'>(</span><span class='str'>&quot;ff00&quot;</span><span class='op'>,</span> <span class='num'>16</span><span class='op'>)</span><span class='op'>)</span><span class='op'>,</span> <span class='nam'>result</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>self</span><span class='op'>.</span><span class='nam'>assertEqual</span><span class='op'>(</span><span class='op'>(</span><span class='num'>1</span><span class='op'>,</span><span class='op'>)</span><span class='op'>,</span> <span class='nam'>self</span><span class='op'>.</span><span class='nam'>slave1</span><span class='op'>.</span><span class='nam'>get_values</span><span class='op'>(</span><span class='str'>&quot;c0-100&quot;</span><span class='op'>,</span> <span class='num'>0</span><span class='op'>,</span> <span class='num'>1</span><span class='op'>)</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>result</span> <span class='op'>=</span> <span class='nam'>self</span><span class='op'>.</span><span class='nam'>master</span><span class='op'>.</span><span class='nam'>execute</span><span class='op'>(</span><span class='num'>1</span><span class='op'>,</span> <span class='nam'>modbus_tk</span><span class='op'>.</span><span class='nam'>defines</span><span class='op'>.</span><span class='nam'>WRITE_SINGLE_COIL</span><span class='op'>,</span> <span class='num'>22</span><span class='op'>,</span> <span class='nam'>output_value</span><span class='op'>=</span><span class='num'>1</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>self</span><span class='op'>.</span><span class='nam'>assertEqual</span><span class='op'>(</span><span class='op'>(</span><span class='num'>22</span><span class='op'>,</span> <span class='nam'>int</span><span class='op'>(</span><span class='str'>&quot;ff00&quot;</span><span class='op'>,</span> <span class='num'>16</span><span class='op'>)</span><span class='op'>)</span><span class='op'>,</span> <span class='nam'>result</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>self</span><span class='op'>.</span><span class='nam'>assertEqual</span><span class='op'>(</span><span class='op'>(</span><span class='num'>1</span><span class='op'>,</span><span class='op'>)</span><span class='op'>,</span> <span class='nam'>self</span><span class='op'>.</span><span class='nam'>slave1</span><span class='op'>.</span><span class='nam'>get_values</span><span class='op'>(</span><span class='str'>&quot;c0-100&quot;</span><span class='op'>,</span> <span class='num'>22</span><span class='op'>,</span> <span class='num'>1</span><span class='op'>)</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>result</span> <span class='op'>=</span> <span class='nam'>self</span><span class='op'>.</span><span class='nam'>master</span><span class='op'>.</span><span class='nam'>execute</span><span class='op'>(</span><span class='num'>1</span><span class='op'>,</span> <span class='nam'>modbus_tk</span><span class='op'>.</span><span class='nam'>defines</span><span class='op'>.</span><span class='nam'>WRITE_SINGLE_COIL</span><span class='op'>,</span> <span class='num'>22</span><span class='op'>,</span> <span class='nam'>output_value</span><span class='op'>=</span><span class='num'>0</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>self</span><span class='op'>.</span><span class='nam'>assertEqual</span><span class='op'>(</span><span class='op'>(</span><span class='num'>22</span><span class='op'>,</span> <span class='num'>0</span><span class='op'>)</span><span class='op'>,</span> <span class='nam'>result</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>self</span><span class='op'>.</span><span class='nam'>assertEqual</span><span class='op'>(</span><span class='op'>(</span><span class='num'>0</span><span class='op'>,</span><span class='op'>)</span><span class='op'>,</span> <span class='nam'>self</span><span class='op'>.</span><span class='nam'>slave1</span><span class='op'>.</span><span class='nam'>get_values</span><span class='op'>(</span><span class='str'>&quot;c0-100&quot;</span><span class='op'>,</span> <span class='num'>22</span><span class='op'>,</span> <span class='num'>1</span><span class='op'>)</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; <span class='key'>def</span> <span class='nam'>testWriteSingleCoilOutOfBlocks</span><span class='op'>(</span><span class='nam'>self</span><span class='op'>)</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='pln'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='str'>&quot;&quot;&quot;Check taht an error is raised when writing a coil out of block&quot;&quot;&quot;</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>try</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>self</span><span class='op'>.</span><span class='nam'>master</span><span class='op'>.</span><span class='nam'>execute</span><span class='op'>(</span><span class='num'>1</span><span class='op'>,</span> <span class='nam'>modbus_tk</span><span class='op'>.</span><span class='nam'>defines</span><span class='op'>.</span><span class='nam'>WRITE_SINGLE_COIL</span><span class='op'>,</span> <span class='num'>500</span><span class='op'>,</span> <span class='nam'>output_value</span><span class='op'>=</span><span class='num'>1</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>except</span> <span class='nam'>modbus_tk</span><span class='op'>.</span><span class='nam'>modbus</span><span class='op'>.</span><span class='nam'>ModbusError</span><span class='op'>,</span> <span class='nam'>ex</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>self</span><span class='op'>.</span><span class='nam'>assertEqual</span><span class='op'>(</span><span class='nam'>ex</span><span class='op'>.</span><span class='nam'>get_exception_code</span><span class='op'>(</span><span class='op'>)</span><span class='op'>,</span> <span class='nam'>modbus_tk</span><span class='op'>.</span><span class='nam'>defines</span><span class='op'>.</span><span class='nam'>ILLEGAL_DATA_ADDRESS</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>return</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>self</span><span class='op'>.</span><span class='nam'>assert_</span><span class='op'>(</span><span class='nam'>False</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; <span class='key'>def</span> <span class='nam'>testWriteMultipleRegisters</span><span class='op'>(</span><span class='nam'>self</span><span class='op'>)</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='pln'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='str'>&quot;&quot;&quot;Write the values of a multiple registers and check that it is correctly written&quot;&quot;&quot;</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>result</span> <span class='op'>=</span> <span class='nam'>self</span><span class='op'>.</span><span class='nam'>master</span><span class='op'>.</span><span class='nam'>execute</span><span class='op'>(</span><span class='num'>1</span><span class='op'>,</span> <span class='nam'>modbus_tk</span><span class='op'>.</span><span class='nam'>defines</span><span class='op'>.</span><span class='nam'>WRITE_MULTIPLE_REGISTERS</span><span class='op'>,</span> <span class='num'>0</span><span class='op'>,</span> <span class='nam'>output_value</span><span class='op'>=</span><span class='op'>(</span><span class='num'>54</span><span class='op'>,</span> <span class='op'>)</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>self</span><span class='op'>.</span><span class='nam'>assertEqual</span><span class='op'>(</span><span class='op'>(</span><span class='num'>0</span><span class='op'>,</span> <span class='num'>1</span><span class='op'>)</span><span class='op'>,</span> <span class='nam'>result</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>self</span><span class='op'>.</span><span class='nam'>assertEqual</span><span class='op'>(</span><span class='op'>(</span><span class='num'>54</span><span class='op'>,</span><span class='op'>)</span><span class='op'>,</span> <span class='nam'>self</span><span class='op'>.</span><span class='nam'>slave1</span><span class='op'>.</span><span class='nam'>get_values</span><span class='op'>(</span><span class='str'>&quot;hr0-100&quot;</span><span class='op'>,</span> <span class='num'>0</span><span class='op'>,</span> <span class='num'>1</span><span class='op'>)</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>result</span> <span class='op'>=</span> <span class='nam'>self</span><span class='op'>.</span><span class='nam'>master</span><span class='op'>.</span><span class='nam'>execute</span><span class='op'>(</span><span class='num'>1</span><span class='op'>,</span> <span class='nam'>modbus_tk</span><span class='op'>.</span><span class='nam'>defines</span><span class='op'>.</span><span class='nam'>WRITE_MULTIPLE_REGISTERS</span><span class='op'>,</span> <span class='num'>10</span><span class='op'>,</span> <span class='nam'>output_value</span><span class='op'>=</span><span class='nam'>range</span><span class='op'>(</span><span class='num'>20</span><span class='op'>)</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>self</span><span class='op'>.</span><span class='nam'>assertEqual</span><span class='op'>(</span><span class='op'>(</span><span class='num'>10</span><span class='op'>,</span> <span class='num'>20</span><span class='op'>)</span><span class='op'>,</span> <span class='nam'>result</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>self</span><span class='op'>.</span><span class='nam'>assertEqual</span><span class='op'>(</span><span class='nam'>tuple</span><span class='op'>(</span><span class='nam'>range</span><span class='op'>(</span><span class='num'>20</span><span class='op'>)</span><span class='op'>)</span><span class='op'>,</span> <span class='nam'>self</span><span class='op'>.</span><span class='nam'>slave1</span><span class='op'>.</span><span class='nam'>get_values</span><span class='op'>(</span><span class='str'>&quot;hr0-100&quot;</span><span class='op'>,</span> <span class='num'>10</span><span class='op'>,</span> <span class='num'>20</span><span class='op'>)</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>result</span> <span class='op'>=</span> <span class='nam'>self</span><span class='op'>.</span><span class='nam'>master</span><span class='op'>.</span><span class='nam'>execute</span><span class='op'>(</span><span class='num'>1</span><span class='op'>,</span> <span class='nam'>modbus_tk</span><span class='op'>.</span><span class='nam'>defines</span><span class='op'>.</span><span class='nam'>WRITE_MULTIPLE_REGISTERS</span><span class='op'>,</span> <span class='num'>1000</span><span class='op'>,</span> <span class='nam'>output_value</span><span class='op'>=</span><span class='nam'>range</span><span class='op'>(</span><span class='num'>123</span><span class='op'>)</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>self</span><span class='op'>.</span><span class='nam'>assertEqual</span><span class='op'>(</span><span class='op'>(</span><span class='num'>1000</span><span class='op'>,</span> <span class='num'>123</span><span class='op'>)</span><span class='op'>,</span> <span class='nam'>result</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>self</span><span class='op'>.</span><span class='nam'>assertEqual</span><span class='op'>(</span><span class='nam'>tuple</span><span class='op'>(</span><span class='nam'>range</span><span class='op'>(</span><span class='num'>123</span><span class='op'>)</span><span class='op'>)</span><span class='op'>,</span> <span class='nam'>self</span><span class='op'>.</span><span class='nam'>slave1</span><span class='op'>.</span><span class='nam'>get_values</span><span class='op'>(</span><span class='str'>&quot;hr1000-1500&quot;</span><span class='op'>,</span> <span class='num'>1000</span><span class='op'>,</span> <span class='num'>123</span><span class='op'>)</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; <span class='key'>def</span> <span class='nam'>testWriteMultipleRegistersOutOfBlocks</span><span class='op'>(</span><span class='nam'>self</span><span class='op'>)</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='pln'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='str'>&quot;&quot;&quot;Check that an error is raised when writing a register out of block&quot;&quot;&quot;</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>try</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>self</span><span class='op'>.</span><span class='nam'>master</span><span class='op'>.</span><span class='nam'>execute</span><span class='op'>(</span><span class='num'>1</span><span class='op'>,</span> <span class='nam'>modbus_tk</span><span class='op'>.</span><span class='nam'>defines</span><span class='op'>.</span><span class='nam'>WRITE_MULTIPLE_REGISTERS</span><span class='op'>,</span> <span class='num'>500</span><span class='op'>,</span> <span class='nam'>output_value</span><span class='op'>=</span><span class='op'>(</span><span class='num'>11</span><span class='op'>,</span> <span class='num'>12</span><span class='op'>)</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>except</span> <span class='nam'>modbus_tk</span><span class='op'>.</span><span class='nam'>modbus</span><span class='op'>.</span><span class='nam'>ModbusError</span><span class='op'>,</span> <span class='nam'>ex</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>self</span><span class='op'>.</span><span class='nam'>assertEqual</span><span class='op'>(</span><span class='nam'>ex</span><span class='op'>.</span><span class='nam'>get_exception_code</span><span class='op'>(</span><span class='op'>)</span><span class='op'>,</span> <span class='nam'>modbus_tk</span><span class='op'>.</span><span class='nam'>defines</span><span class='op'>.</span><span class='nam'>ILLEGAL_DATA_ADDRESS</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>return</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>self</span><span class='op'>.</span><span class='nam'>assert_</span><span class='op'>(</span><span class='nam'>False</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; <span class='key'>def</span> <span class='nam'>testWriteTooManyMultipleRegisters</span><span class='op'>(</span><span class='nam'>self</span><span class='op'>)</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='pln'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='str'>&quot;&quot;&quot;Check that an error is raised when writing too many registers&quot;&quot;&quot;</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>try</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>self</span><span class='op'>.</span><span class='nam'>master</span><span class='op'>.</span><span class='nam'>execute</span><span class='op'>(</span><span class='num'>1</span><span class='op'>,</span> <span class='nam'>modbus_tk</span><span class='op'>.</span><span class='nam'>defines</span><span class='op'>.</span><span class='nam'>WRITE_MULTIPLE_REGISTERS</span><span class='op'>,</span> <span class='num'>1000</span><span class='op'>,</span> <span class='nam'>output_value</span><span class='op'>=</span><span class='nam'>range</span><span class='op'>(</span><span class='num'>124</span><span class='op'>)</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>except</span> <span class='nam'>modbus_tk</span><span class='op'>.</span><span class='nam'>modbus</span><span class='op'>.</span><span class='nam'>ModbusError</span><span class='op'>,</span> <span class='nam'>ex</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>self</span><span class='op'>.</span><span class='nam'>assertEqual</span><span class='op'>(</span><span class='nam'>ex</span><span class='op'>.</span><span class='nam'>get_exception_code</span><span class='op'>(</span><span class='op'>)</span><span class='op'>,</span> <span class='nam'>modbus_tk</span><span class='op'>.</span><span class='nam'>defines</span><span class='op'>.</span><span class='nam'>ILLEGAL_DATA_VALUE</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>return</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>self</span><span class='op'>.</span><span class='nam'>assert_</span><span class='op'>(</span><span class='nam'>False</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; <span class='key'>def</span> <span class='nam'>testWriteMultipleCoils</span><span class='op'>(</span><span class='nam'>self</span><span class='op'>)</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='pln'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='str'>&quot;&quot;&quot;Write the values of a multiple coils and check that it is correctly written&quot;&quot;&quot;</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>result</span> <span class='op'>=</span> <span class='nam'>self</span><span class='op'>.</span><span class='nam'>master</span><span class='op'>.</span><span class='nam'>execute</span><span class='op'>(</span><span class='num'>1</span><span class='op'>,</span> <span class='nam'>modbus_tk</span><span class='op'>.</span><span class='nam'>defines</span><span class='op'>.</span><span class='nam'>WRITE_MULTIPLE_COILS</span><span class='op'>,</span> <span class='num'>0</span><span class='op'>,</span> <span class='nam'>output_value</span><span class='op'>=</span><span class='op'>(</span><span class='num'>1</span><span class='op'>,</span> <span class='op'>)</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>self</span><span class='op'>.</span><span class='nam'>assertEqual</span><span class='op'>(</span><span class='op'>(</span><span class='num'>0</span><span class='op'>,</span> <span class='num'>1</span><span class='op'>)</span><span class='op'>,</span> <span class='nam'>result</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>self</span><span class='op'>.</span><span class='nam'>assertEqual</span><span class='op'>(</span><span class='op'>(</span><span class='num'>1</span><span class='op'>,</span><span class='op'>)</span><span class='op'>,</span> <span class='nam'>self</span><span class='op'>.</span><span class='nam'>slave1</span><span class='op'>.</span><span class='nam'>get_values</span><span class='op'>(</span><span class='str'>&quot;c0-100&quot;</span><span class='op'>,</span> <span class='num'>0</span><span class='op'>,</span> <span class='num'>1</span><span class='op'>)</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>result</span> <span class='op'>=</span> <span class='nam'>self</span><span class='op'>.</span><span class='nam'>master</span><span class='op'>.</span><span class='nam'>execute</span><span class='op'>(</span><span class='num'>1</span><span class='op'>,</span> <span class='nam'>modbus_tk</span><span class='op'>.</span><span class='nam'>defines</span><span class='op'>.</span><span class='nam'>WRITE_MULTIPLE_COILS</span><span class='op'>,</span> <span class='num'>10</span><span class='op'>,</span> <span class='nam'>output_value</span><span class='op'>=</span><span class='op'>[</span><span class='num'>1</span><span class='op'>]</span><span class='op'>*</span><span class='num'>20</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>self</span><span class='op'>.</span><span class='nam'>assertEqual</span><span class='op'>(</span><span class='op'>(</span><span class='num'>10</span><span class='op'>,</span> <span class='num'>20</span><span class='op'>)</span><span class='op'>,</span> <span class='nam'>result</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>self</span><span class='op'>.</span><span class='nam'>assertEqual</span><span class='op'>(</span><span class='nam'>tuple</span><span class='op'>(</span><span class='op'>[</span><span class='num'>1</span><span class='op'>]</span><span class='op'>*</span><span class='num'>20</span><span class='op'>)</span><span class='op'>,</span> <span class='nam'>self</span><span class='op'>.</span><span class='nam'>slave1</span><span class='op'>.</span><span class='nam'>get_values</span><span class='op'>(</span><span class='str'>&quot;c0-100&quot;</span><span class='op'>,</span> <span class='num'>10</span><span class='op'>,</span> <span class='num'>20</span><span class='op'>)</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>result</span> <span class='op'>=</span> <span class='nam'>self</span><span class='op'>.</span><span class='nam'>master</span><span class='op'>.</span><span class='nam'>execute</span><span class='op'>(</span><span class='num'>1</span><span class='op'>,</span> <span class='nam'>modbus_tk</span><span class='op'>.</span><span class='nam'>defines</span><span class='op'>.</span><span class='nam'>WRITE_MULTIPLE_COILS</span><span class='op'>,</span> <span class='num'>1000</span><span class='op'>,</span> <span class='nam'>output_value</span><span class='op'>=</span><span class='op'>[</span><span class='num'>1</span><span class='op'>]</span><span class='op'>*</span><span class='num'>1968</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>self</span><span class='op'>.</span><span class='nam'>assertEqual</span><span class='op'>(</span><span class='op'>(</span><span class='num'>1000</span><span class='op'>,</span> <span class='num'>1968</span><span class='op'>)</span><span class='op'>,</span> <span class='nam'>result</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>self</span><span class='op'>.</span><span class='nam'>assertEqual</span><span class='op'>(</span><span class='nam'>tuple</span><span class='op'>(</span><span class='op'>[</span><span class='num'>1</span><span class='op'>]</span><span class='op'>*</span><span class='num'>1968</span><span class='op'>)</span><span class='op'>,</span> <span class='nam'>self</span><span class='op'>.</span><span class='nam'>slave1</span><span class='op'>.</span><span class='nam'>get_values</span><span class='op'>(</span><span class='str'>&quot;c1000-4000&quot;</span><span class='op'>,</span> <span class='num'>1000</span><span class='op'>,</span> <span class='num'>1968</span><span class='op'>)</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; <span class='key'>def</span> <span class='nam'>testWriteMultipleCoilsOutOfBlocks</span><span class='op'>(</span><span class='nam'>self</span><span class='op'>)</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='pln'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='str'>&quot;&quot;&quot;Check that an error is raised when writing a register out of block&quot;&quot;&quot;</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>try</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>self</span><span class='op'>.</span><span class='nam'>master</span><span class='op'>.</span><span class='nam'>execute</span><span class='op'>(</span><span class='num'>1</span><span class='op'>,</span> <span class='nam'>modbus_tk</span><span class='op'>.</span><span class='nam'>defines</span><span class='op'>.</span><span class='nam'>WRITE_MULTIPLE_COILS</span><span class='op'>,</span> <span class='num'>500</span><span class='op'>,</span> <span class='nam'>output_value</span><span class='op'>=</span><span class='op'>(</span><span class='num'>11</span><span class='op'>,</span> <span class='num'>12</span><span class='op'>)</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>except</span> <span class='nam'>modbus_tk</span><span class='op'>.</span><span class='nam'>modbus</span><span class='op'>.</span><span class='nam'>ModbusError</span><span class='op'>,</span> <span class='nam'>ex</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>self</span><span class='op'>.</span><span class='nam'>assertEqual</span><span class='op'>(</span><span class='nam'>ex</span><span class='op'>.</span><span class='nam'>get_exception_code</span><span class='op'>(</span><span class='op'>)</span><span class='op'>,</span> <span class='nam'>modbus_tk</span><span class='op'>.</span><span class='nam'>defines</span><span class='op'>.</span><span class='nam'>ILLEGAL_DATA_ADDRESS</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>return</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>self</span><span class='op'>.</span><span class='nam'>assert_</span><span class='op'>(</span><span class='nam'>False</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; <span class='key'>def</span> <span class='nam'>testWriteTooManyMultipleCoils</span><span class='op'>(</span><span class='nam'>self</span><span class='op'>)</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='pln'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='str'>&quot;&quot;&quot;Check that an error is raised when writing too many registers&quot;&quot;&quot;</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>try</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>self</span><span class='op'>.</span><span class='nam'>master</span><span class='op'>.</span><span class='nam'>execute</span><span class='op'>(</span><span class='num'>1</span><span class='op'>,</span> <span class='nam'>modbus_tk</span><span class='op'>.</span><span class='nam'>defines</span><span class='op'>.</span><span class='nam'>WRITE_MULTIPLE_COILS</span><span class='op'>,</span> <span class='num'>1000</span><span class='op'>,</span> <span class='nam'>output_value</span><span class='op'>=</span><span class='op'>[</span><span class='num'>1</span><span class='op'>]</span><span class='op'>*</span><span class='op'>(</span><span class='nam'>int</span><span class='op'>(</span><span class='str'>&quot;7B0&quot;</span><span class='op'>,</span> <span class='num'>16</span><span class='op'>)</span><span class='op'>+</span><span class='num'>1</span><span class='op'>)</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>except</span> <span class='nam'>modbus_tk</span><span class='op'>.</span><span class='nam'>modbus</span><span class='op'>.</span><span class='nam'>ModbusError</span><span class='op'>,</span> <span class='nam'>ex</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>self</span><span class='op'>.</span><span class='nam'>assertEqual</span><span class='op'>(</span><span class='nam'>ex</span><span class='op'>.</span><span class='nam'>get_exception_code</span><span class='op'>(</span><span class='op'>)</span><span class='op'>,</span> <span class='nam'>modbus_tk</span><span class='op'>.</span><span class='nam'>defines</span><span class='op'>.</span><span class='nam'>ILLEGAL_DATA_VALUE</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>return</span><span class='strut'>&nbsp;</span></p>
<p class='stm mis'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>self</span><span class='op'>.</span><span class='nam'>assert_</span><span class='op'>(</span><span class='nam'>False</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; <span class='key'>def</span> <span class='nam'>testBroadcast</span><span class='op'>(</span><span class='nam'>self</span><span class='op'>)</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='pln'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='str'>&quot;&quot;&quot;Check that broadcast queries are handled correctly&quot;&quot;&quot;</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>self</span><span class='op'>.</span><span class='nam'>slave1</span><span class='op'>.</span><span class='nam'>add_block</span><span class='op'>(</span><span class='str'>&quot;D&quot;</span><span class='op'>,</span> <span class='nam'>modbus_tk</span><span class='op'>.</span><span class='nam'>defines</span><span class='op'>.</span><span class='nam'>COILS</span><span class='op'>,</span> <span class='num'>5000</span><span class='op'>,</span> <span class='num'>50</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>self</span><span class='op'>.</span><span class='nam'>slave1</span><span class='op'>.</span><span class='nam'>add_block</span><span class='op'>(</span><span class='str'>&quot;A&quot;</span><span class='op'>,</span> <span class='nam'>modbus_tk</span><span class='op'>.</span><span class='nam'>defines</span><span class='op'>.</span><span class='nam'>HOLDING_REGISTERS</span><span class='op'>,</span> <span class='num'>5000</span><span class='op'>,</span> <span class='num'>50</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>self</span><span class='op'>.</span><span class='nam'>slave5</span><span class='op'>.</span><span class='nam'>add_block</span><span class='op'>(</span><span class='str'>&quot;D&quot;</span><span class='op'>,</span> <span class='nam'>modbus_tk</span><span class='op'>.</span><span class='nam'>defines</span><span class='op'>.</span><span class='nam'>COILS</span><span class='op'>,</span> <span class='num'>5000</span><span class='op'>,</span> <span class='num'>50</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>self</span><span class='op'>.</span><span class='nam'>slave5</span><span class='op'>.</span><span class='nam'>add_block</span><span class='op'>(</span><span class='str'>&quot;A&quot;</span><span class='op'>,</span> <span class='nam'>modbus_tk</span><span class='op'>.</span><span class='nam'>defines</span><span class='op'>.</span><span class='nam'>HOLDING_REGISTERS</span><span class='op'>,</span> <span class='num'>5000</span><span class='op'>,</span> <span class='num'>50</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>self</span><span class='op'>.</span><span class='nam'>master</span><span class='op'>.</span><span class='nam'>execute</span><span class='op'>(</span><span class='num'>0</span><span class='op'>,</span> <span class='nam'>modbus_tk</span><span class='op'>.</span><span class='nam'>defines</span><span class='op'>.</span><span class='nam'>WRITE_MULTIPLE_REGISTERS</span><span class='op'>,</span> <span class='num'>5000</span><span class='op'>,</span> <span class='nam'>output_value</span><span class='op'>=</span><span class='nam'>range</span><span class='op'>(</span><span class='num'>20</span><span class='op'>)</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>time</span><span class='op'>.</span><span class='nam'>sleep</span><span class='op'>(</span><span class='num'>0.5</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>self</span><span class='op'>.</span><span class='nam'>master</span><span class='op'>.</span><span class='nam'>execute</span><span class='op'>(</span><span class='num'>0</span><span class='op'>,</span> <span class='nam'>modbus_tk</span><span class='op'>.</span><span class='nam'>defines</span><span class='op'>.</span><span class='nam'>WRITE_SINGLE_REGISTER</span><span class='op'>,</span> <span class='num'>5030</span><span class='op'>,</span> <span class='nam'>output_value</span><span class='op'>=</span><span class='num'>12</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>time</span><span class='op'>.</span><span class='nam'>sleep</span><span class='op'>(</span><span class='num'>0.5</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>self</span><span class='op'>.</span><span class='nam'>master</span><span class='op'>.</span><span class='nam'>execute</span><span class='op'>(</span><span class='num'>0</span><span class='op'>,</span> <span class='nam'>modbus_tk</span><span class='op'>.</span><span class='nam'>defines</span><span class='op'>.</span><span class='nam'>WRITE_MULTIPLE_COILS</span><span class='op'>,</span> <span class='num'>5000</span><span class='op'>,</span> <span class='nam'>output_value</span><span class='op'>=</span><span class='nam'>tuple</span><span class='op'>(</span><span class='op'>[</span><span class='num'>1</span><span class='op'>]</span><span class='op'>*</span><span class='num'>10</span><span class='op'>)</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>time</span><span class='op'>.</span><span class='nam'>sleep</span><span class='op'>(</span><span class='num'>0.5</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>self</span><span class='op'>.</span><span class='nam'>master</span><span class='op'>.</span><span class='nam'>execute</span><span class='op'>(</span><span class='num'>0</span><span class='op'>,</span> <span class='nam'>modbus_tk</span><span class='op'>.</span><span class='nam'>defines</span><span class='op'>.</span><span class='nam'>WRITE_SINGLE_COIL</span><span class='op'>,</span> <span class='num'>5030</span><span class='op'>,</span> <span class='nam'>output_value</span><span class='op'>=</span><span class='num'>1</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>time</span><span class='op'>.</span><span class='nam'>sleep</span><span class='op'>(</span><span class='num'>0.5</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>self</span><span class='op'>.</span><span class='nam'>assertEqual</span><span class='op'>(</span><span class='nam'>self</span><span class='op'>.</span><span class='nam'>slave1</span><span class='op'>.</span><span class='nam'>get_values</span><span class='op'>(</span><span class='str'>&quot;A&quot;</span><span class='op'>,</span> <span class='num'>5000</span><span class='op'>,</span> <span class='num'>20</span><span class='op'>)</span><span class='op'>,</span> <span class='nam'>tuple</span><span class='op'>(</span><span class='nam'>range</span><span class='op'>(</span><span class='num'>20</span><span class='op'>)</span><span class='op'>)</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>self</span><span class='op'>.</span><span class='nam'>assertEqual</span><span class='op'>(</span><span class='nam'>self</span><span class='op'>.</span><span class='nam'>slave5</span><span class='op'>.</span><span class='nam'>get_values</span><span class='op'>(</span><span class='str'>&quot;A&quot;</span><span class='op'>,</span> <span class='num'>5000</span><span class='op'>,</span> <span class='num'>20</span><span class='op'>)</span><span class='op'>,</span> <span class='nam'>tuple</span><span class='op'>(</span><span class='nam'>range</span><span class='op'>(</span><span class='num'>20</span><span class='op'>)</span><span class='op'>)</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>self</span><span class='op'>.</span><span class='nam'>assertEqual</span><span class='op'>(</span><span class='nam'>self</span><span class='op'>.</span><span class='nam'>slave1</span><span class='op'>.</span><span class='nam'>get_values</span><span class='op'>(</span><span class='str'>&quot;A&quot;</span><span class='op'>,</span> <span class='num'>5030</span><span class='op'>,</span> <span class='num'>1</span><span class='op'>)</span><span class='op'>,</span> <span class='op'>(</span><span class='num'>12</span><span class='op'>,</span><span class='op'>)</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>self</span><span class='op'>.</span><span class='nam'>assertEqual</span><span class='op'>(</span><span class='nam'>self</span><span class='op'>.</span><span class='nam'>slave5</span><span class='op'>.</span><span class='nam'>get_values</span><span class='op'>(</span><span class='str'>&quot;A&quot;</span><span class='op'>,</span> <span class='num'>5030</span><span class='op'>,</span> <span class='num'>1</span><span class='op'>)</span><span class='op'>,</span> <span class='op'>(</span><span class='num'>12</span><span class='op'>,</span><span class='op'>)</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>self</span><span class='op'>.</span><span class='nam'>assertEqual</span><span class='op'>(</span><span class='nam'>self</span><span class='op'>.</span><span class='nam'>slave1</span><span class='op'>.</span><span class='nam'>get_values</span><span class='op'>(</span><span class='str'>&quot;D&quot;</span><span class='op'>,</span> <span class='num'>5000</span><span class='op'>,</span> <span class='num'>10</span><span class='op'>)</span><span class='op'>,</span> <span class='nam'>tuple</span><span class='op'>(</span><span class='op'>[</span><span class='num'>1</span><span class='op'>]</span><span class='op'>*</span><span class='num'>10</span><span class='op'>)</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>self</span><span class='op'>.</span><span class='nam'>assertEqual</span><span class='op'>(</span><span class='nam'>self</span><span class='op'>.</span><span class='nam'>slave5</span><span class='op'>.</span><span class='nam'>get_values</span><span class='op'>(</span><span class='str'>&quot;D&quot;</span><span class='op'>,</span> <span class='num'>5000</span><span class='op'>,</span> <span class='num'>10</span><span class='op'>)</span><span class='op'>,</span> <span class='nam'>tuple</span><span class='op'>(</span><span class='op'>[</span><span class='num'>1</span><span class='op'>]</span><span class='op'>*</span><span class='num'>10</span><span class='op'>)</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>self</span><span class='op'>.</span><span class='nam'>assertEqual</span><span class='op'>(</span><span class='nam'>self</span><span class='op'>.</span><span class='nam'>slave1</span><span class='op'>.</span><span class='nam'>get_values</span><span class='op'>(</span><span class='str'>&quot;D&quot;</span><span class='op'>,</span> <span class='num'>5030</span><span class='op'>,</span> <span class='num'>1</span><span class='op'>)</span><span class='op'>,</span> <span class='op'>(</span><span class='num'>1</span><span class='op'>,</span><span class='op'>)</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>self</span><span class='op'>.</span><span class='nam'>assertEqual</span><span class='op'>(</span><span class='nam'>self</span><span class='op'>.</span><span class='nam'>slave5</span><span class='op'>.</span><span class='nam'>get_values</span><span class='op'>(</span><span class='str'>&quot;D&quot;</span><span class='op'>,</span> <span class='num'>5030</span><span class='op'>,</span> <span class='num'>1</span><span class='op'>)</span><span class='op'>,</span> <span class='op'>(</span><span class='num'>1</span><span class='op'>,</span><span class='op'>)</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; <span class='key'>def</span> <span class='nam'>testBroadcastReading</span><span class='op'>(</span><span class='nam'>self</span><span class='op'>)</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='pln'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='str'>&quot;&quot;&quot;Check that broadcast queries are handled correctly&quot;&quot;&quot;</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>functions</span> <span class='op'>=</span> <span class='op'>(</span><span class='nam'>modbus_tk</span><span class='op'>.</span><span class='nam'>defines</span><span class='op'>.</span><span class='nam'>READ_HOLDING_REGISTERS</span><span class='op'>,</span> <span class='nam'>modbus_tk</span><span class='op'>.</span><span class='nam'>defines</span><span class='op'>.</span><span class='nam'>READ_COILS</span><span class='op'>,</span><span class='strut'>&nbsp;</span></p>
<p class='pln'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>modbus_tk</span><span class='op'>.</span><span class='nam'>defines</span><span class='op'>.</span><span class='nam'>READ_INPUT_REGISTERS</span><span class='op'>,</span> <span class='nam'>modbus_tk</span><span class='op'>.</span><span class='nam'>defines</span><span class='op'>.</span><span class='nam'>READ_DISCRETE_INPUTS</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>for</span> <span class='nam'>fct</span> <span class='key'>in</span> <span class='nam'>functions</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>self</span><span class='op'>.</span><span class='nam'>assertEqual</span><span class='op'>(</span><span class='nam'>None</span><span class='op'>,</span> <span class='nam'>self</span><span class='op'>.</span><span class='nam'>master</span><span class='op'>.</span><span class='nam'>execute</span><span class='op'>(</span><span class='num'>0</span><span class='op'>,</span> <span class='nam'>fct</span><span class='op'>,</span> <span class='num'>0</span><span class='op'>,</span> <span class='num'>5</span><span class='op'>)</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; <span class='key'>def</span> <span class='nam'>testInvalidRequest</span><span class='op'>(</span><span class='nam'>self</span><span class='op'>)</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='pln'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='str'>&quot;&quot;&quot;Check that an error is returned when the request is invalid&quot;&quot;&quot;</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>query</span> <span class='op'>=</span> <span class='nam'>self</span><span class='op'>.</span><span class='nam'>server</span><span class='op'>.</span><span class='nam'>_make_query</span><span class='op'>(</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>requests</span> <span class='op'>=</span> <span class='op'>(</span><span class='op'>(</span><span class='nam'>chr</span><span class='op'>(</span><span class='num'>1</span><span class='op'>)</span><span class='op'>,</span> <span class='num'>0x81</span><span class='op'>)</span><span class='op'>,</span> <span class='op'>(</span><span class='nam'>chr</span><span class='op'>(</span><span class='num'>3</span><span class='op'>)</span><span class='op'>,</span> <span class='num'>0x83</span><span class='op'>)</span><span class='op'>,</span> <span class='op'>(</span><span class='str'>&quot;&quot;</span><span class='op'>,</span> <span class='num'>0x81</span><span class='op'>)</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; <span class='key'>for</span> <span class='op'>(</span><span class='nam'>request_pdu</span><span class='op'>,</span> <span class='nam'>rc</span><span class='op'>)</span> <span class='key'>in</span> <span class='nam'>requests</span><span class='op'>:</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>request</span> <span class='op'>=</span> <span class='nam'>query</span><span class='op'>.</span><span class='nam'>build_request</span><span class='op'>(</span><span class='nam'>request_pdu</span><span class='op'>,</span> <span class='num'>1</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>response</span> <span class='op'>=</span> <span class='nam'>self</span><span class='op'>.</span><span class='nam'>server</span><span class='op'>.</span><span class='nam'>_databank</span><span class='op'>.</span><span class='nam'>handle_request</span><span class='op'>(</span><span class='nam'>query</span><span class='op'>,</span> <span class='nam'>request</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>expected_response</span> <span class='op'>=</span> <span class='nam'>struct</span><span class='op'>.</span><span class='nam'>pack</span><span class='op'>(</span><span class='str'>&quot;&gt;BB&quot;</span><span class='op'>,</span> <span class='nam'>rc</span><span class='op'>,</span> <span class='nam'>modbus_tk</span><span class='op'>.</span><span class='nam'>defines</span><span class='op'>.</span><span class='nam'>SLAVE_DEVICE_FAILURE</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='stm run hide_run'>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class='nam'>self</span><span class='op'>.</span><span class='nam'>assertEquals</span><span class='op'>(</span><span class='nam'>expected_response</span><span class='op'>,</span> <span class='nam'>response</span><span class='op'>)</span><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
<p class='pln'><span class='strut'>&nbsp;</span></p>
    
</td>
</tr>
</table>
</div>

</body>
</html>
